Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4
The 'and' and 'or' operators take two expressions and evaluate their boolean value. The first expression 4>=1 is True The second expression is purely a number, and all numbers except 0 have True value in Python. 'and' returns the second expression if the first one is true. Thats why the result is 3. 'if' returns the first expression if it is true, otherwise the second expression. In this case it is evaluated to True. This is just how these built in operators are implemented. Their 'normal' usage is to compare two logical expressions which is more straightforward.
9th Mar 2019, 3:57 PM
Tibor Santa
Tibor Santa - avatar