Why is >>>True or False >>> True? And why is >>>5 or 7 >>>5 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is >>>True or False >>> True? And why is >>>5 or 7 >>>5

27th Apr 2020, 9:25 AM
Samuel
Samuel - avatar
3 Answers
+ 4
FOR THE FIRST STATEMENT: or operator evaluates to True if either (or both) of its arguments are True, and False if both arguments are False. FOR THE SECOND STATEMENT (5or7) If you’re testing two objects using or , then the operator will return the first object that evaluates to true . For e.g.: Input:6 or 8 output: 6 Input:0 or 8 output: 8 Input:9 or 0 output: 9 I HOPE IT HELPS!🙂
27th Apr 2020, 9:41 AM
ANJALI SAHU
+ 6
The first part: Why is True or False>>>True The code looks at the options, the first option is true, so return >>>True Once it has a true result, it stops looking for another result. So 5 or 7? What is the first True result? 5
27th Apr 2020, 9:37 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Thanks to both of you! 👍 I just found out that most values evaluate to True except 0 and empty strings, arrays. Now it all makes sense
27th Apr 2020, 9:49 AM
Samuel
Samuel - avatar