+ 1

Why doesn't the value of this code come out as False? How can I get the value of this code to come out as False?

a=5 print(a and 0) maybe the 0 is the problem, I want to use 0 as a bool code, but it doesn't recognize as a bool

11th Jul 2024, 12:08 PM
Hawon
Hawon - avatar
1 ответ
+ 4
What the 'and' logical operator really does is that it returns the first "falsey" value of its two operands, otherwise it returns the last value. To get False printed, you can convert the result to boolean directly with the bool() function. print(bool(a and 0))
11th Jul 2024, 12:22 PM
Tibor Santa
Tibor Santa - avatar