Mega Code Archive

 
Categories / Python / Language Basics
 

When the and-or Trick Fails

a = ""  b = "second"  print 1 and a or b # Since a is an empty string, which is false in a boolean context,  #1 and '' evaluates to '', and then '' or 'second' evaluates to 'second'.