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...

21st Mar 2019, 5:38 PM
Ashutosh Dash
Ashutosh Dash - avatar
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)
21st Mar 2019, 6:02 PM
Charlie S
Charlie S - avatar
+ 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.
22nd Mar 2019, 10:46 AM
Charlie S
Charlie S - avatar
0
Charlie S thanks for the response, but can you tell how python thinks when i write nothing after the "if" keyword?
22nd Mar 2019, 9:36 AM
Ashutosh Dash
Ashutosh Dash - avatar
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?
24th Mar 2019, 12:05 PM
Ashutosh Dash
Ashutosh Dash - avatar