+ 5

Why the following code evaluates to zero? Why not False? print(False or 0)

6th Oct 2017, 7:59 AM
Aravind Shetty
Aravind Shetty - avatar
4 Respostas
+ 2
there is no distinction between them, so if you try print(0 or False) you will get False
6th Oct 2017, 12:39 PM
Danis
Danis - avatar
+ 2
some more explanation: The expression x and y first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned. because both of them are False, 'print()' will print a second value.
6th Oct 2017, 12:46 PM
Danis
Danis - avatar
0
So the second one will be the output.
6th Oct 2017, 12:45 PM
Aravind Shetty
Aravind Shetty - avatar
0
thank you!
6th Oct 2017, 12:49 PM
Aravind Shetty
Aravind Shetty - avatar