0

I am complete noob in python. I was trying to figure out working with tuples. So, I did the following and I do not understand the result.

n=12        
m = (0,1,2)

print n and m   
# Result  (0, 1, 2)

print n or m  
# Result 12

This might have been asked before but I couldn't find any related.

MSeifert
  • 145,886
  • 38
  • 333
  • 352
Invariance
  • 313
  • 6
  • 16
  • The boolean operations short-circuit in Python: https://stackoverflow.com/questions/2580136/does-python-support-short-circuiting. In other words if the first operand is truthy, then `or` has no need to evaluate the second operand. Similarly if it is falsy then `and` has no need to evaluate the second. – Ilja Everilä Aug 30 '17 at 10:43
  • 1
    This is documented in case you want to read what the official documentation says about it: ["Expressions: Boolean operations"](https://docs.python.org/3/reference/expressions.html#boolean-operations) – MSeifert Aug 30 '17 at 10:45

0 Answers0