python 3.x - Conditional statement with empty string -


why '' , not '123' evaluate '' instead of false, not '123' , '' evaluates false in python 3.4.3?

the logical and/or operators stop evaluating terms (short-circuit) answer decided.

examples and

>>> '' , not '123' '' 

the first 1 false, and short-circuited , first 1 returned.

>>> not '123' , '' false 

not '123' returns false. since false, and short-circuited , result of not '123' 1 returned.

for same reason, following returns zero:

>>> 0 , '123' 0 

and following returns []:

>>> [] , '123' [] 

examples or

>>> '' or '123' '123' >>> not '123' or 'hi' 'hi' >>> '123' or 'hi' '123' 

documentation

this behavior specified in the documentation where:

  • x or y defined if x false, y, else x

  • x , y defined if x false, x, else y

  • not x defined if x false, true, else false


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -