Short-circuit Logic

Ahmed Abdulshafy abdulshafy at gmail.com
Mon May 27 16:08:34 EDT 2013


On Sunday, May 26, 2013 1:11:56 PM UTC+2, Ahmed Abdulshafy wrote:
> Hi,
> 
> I'm having a hard time wrapping my head around short-circuit logic that's used by Python, coming from a C/C++ background; so I don't understand why the following condition is written this way!>
> 
> 
> 
>      if not allow_zero and abs(x) < sys.float_info.epsilon:
> 
>                 print("zero is not allowed")
> 
> 
> 
> The purpose of this snippet is to print the given line when allow_zero is False and x is 0.

Thank you guys! you gave me valuable insights! But regarding my original post, I don't know why for the past two days I was looking at the code *only* this way>
     if ( not allow_zero and abs(x) ) < sys.float_info.epsilon:

I feel so stupid now :-/, may be it's the new syntax confusing me :)! Thanks again guys.



More information about the Python-list mailing list