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 []
1. | And or with values in a list | ||
2. | Introducing and | ||
3. | Introducing or | ||
4. | Using the and-or Trick | ||
5. | When the and-or Trick Fails | ||
6. | Using the and-or Trick Safely |