0

If “x”:

If I make a piece of code that goes If “x”: print(“I’m a penguin”) And I run the code, the message is printed Why? What does if “x”: actually mean? I haven’t given x any value, so what about this undefined x causes the print function to work?

9th Jan 2020, 2:50 AM
laurence astley
1 Answer
+ 1
Didn't work when I tested it in Playground. Error "Invalid character ..." (Edit) Apparently the problem lied in the print function call. You are using a slanted double quote for the string "I'm a penguin". It works as I changed that to regular double quote character. Apparently "x" here is a string, Python considers it as boolean True because it is not an empty string.
9th Jan 2020, 3:04 AM
Ipang