0
Question about print
print(false or true) >>true likewise, print(true or true) >>true Any explanation about why it always print true? I don’t understand how does printing a “or” statement makes sense
3 ответов
+ 5
because or operator returns first operand if it is true, and or operator returns second operand if the first operand is false
Try
print ( 2 or 0)
and
print ( "hi" or "hello")
and
print ( 0 or "this")
+ 3
Yes.
Yes, all strings and non-zero integer is true.
For false, null and undefined are interpreted as false too.
And operator operates similarly. If the first one is false, it returns the first operand; if the first operand is true, it returns the second operand.
+ 2
Gordon Thanks for answering my question anyway.
So in this case,
print(0 or 2)
0 is false so it will print the second operand which is 2
so the first operand is the one who determine which to print.
If my understanding is correct,
is it just false and 0 that stand for false or there are other things that stand for false too?
one more little question, so all the strings and intergers(not 0)
stand for true?