0

not quiet clearly for me

what exactly happened if I type print(2+1 or 4). is it make sense? or it is rave?

3rd Nov 2016, 1:28 PM
Matvey Khamidulin
Matvey Khamidulin - avatar
2 Answers
+ 2
+ operator has a higher precedence them the or operator and thus 2+1 is calculated first. Now you have "3 or 4". The or operator will return the first value if that value is interpreted as true, ou the second value otherwise. Since a nonzero number counts as true then the code will print 3. If the code was "print(2-2 or 4)" then it would print 4.
3rd Nov 2016, 2:06 PM
Darlan Cavalcante Moreira
Darlan Cavalcante Moreira - avatar
0
thanks a lot!
3rd Nov 2016, 4:18 PM
Matvey Khamidulin
Matvey Khamidulin - avatar