And Or in Python: int, empty list and empty dictionary : And Or « Language Basics « Python






And Or in Python: int, empty list and empty dictionary

And Or in Python: int, empty list and empty dictionary
print 2 < 3, 3 < 2        # less-than: return 1 or 0 


print 2 or 3, 3 or 2      # return left operand if true
                        # else return right operand (true or false)
print [] or 3

print [] or {}


print 2 and 3, 3 and 2    # return left operand if false
                          # else return right operand (true or false)

print [] and {}


print 3 and []




           
       








Related examples in the same category

1.And or with values in a list And or with values in a list
2.Introducing andIntroducing and
3.Introducing orIntroducing or
4.Using the and-or TrickUsing the and-or Trick
5.When the and-or Trick FailsWhen the and-or Trick Fails
6.Using the and-or Trick Safely