0
what does the following code mean?
x = None if x: print("Do you think None is True") else: print("None is not True...") #output None is not True...
4 Answers
+ 1
None is calculated as 0, and 0 in boolean language means "false". That's why it returns the else statement. (And also, if you didn't know, the if statement doesn't strictly require a condition to work. There can be a bool variable, a function that returns a bool value or the numbers 0 and 1)
+ 1
Like this
if :
print("dhfh")
It wouldn't work
You need at least a boolean value or a number to be converted to bool so the if statement can work. It is in the syntax of every programming language.
0
Charlie S I'm sorry, I'm still not getting it.. .you agree that if doesn't work without boolean, then where is the boolean in the given code?