this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

this code

if X: print("1") means if X is correct then print 1. right?

11th Jan 2017, 6:46 AM
tonkatsu
tonkatsu - avatar
3 Answers
+ 2
Almost. It means "if X is *True*..." That works if X is a boolean (variable or expression), or if it can be coerced into a boolean value.
11th Jan 2017, 6:50 AM
Álvaro
+ 2
yes what you said is correct. X has to be True to print(1) also don't put 1 in brackets '1' because it will be considered as a string(a word) and not as a number. And if also works if x==1 for exemple : X==1 if X: print(2)
11th Jan 2017, 2:26 PM
ramzi
ramzi - avatar
+ 1
thank u so much!
12th Jan 2017, 3:17 PM
tonkatsu
tonkatsu - avatar