Boolean-logic in Python | Sololearn: Learn to code for FREE!

+1

Boolean-logic in Python

I wondered - in python, are numbers not equal to 0 equal True? I decided to check this out and this is what happened: print(1 if 2 else 0) >>> 1 print(1 if 10 else 0) >>> 1 print(1 if -1 else 0) >>> 1 But! print(1 == True) >>> True print(-1 == True) >>> False Can someone answer my question?

7/5/2020 3:12:10 PM

Granger

6 Answers

New Answer

+2

if <any number> or <any variable> is always true, if the value is set. It's kind a not null-condition. The integer representation of a boolean is different from that and this is, what you checked with the last both statements. Only 1 is equal to true.

+2

Sandra Meyer, Martin Taylor, Thank you) sorry that I can not mark both answers as the best

+1

read my name if you know the answer

+1

Can you explain not operator clearly

0

im confused-