What's the difference | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What's the difference

I've seen some codes whereby true or false is interchanged using the values 1 and 0. Mostly i get confused as to what answer i must choose, so i just want clarity maybe with a code example of how to differentiate between the two

2nd Apr 2019, 10:53 AM
Buhle 💃💃💃
Buhle 💃💃💃 - avatar
1 Answer
+ 1
# Standard is using True False keywords, if it is in language, rather than 1 or 0 # python x = 10 print (x == x) # True # but some times is useful use 0 for false a = "variable x = " #not empty string b = "" # empty string if ( len(a) ): x = x+1 print(a + str(x) ) # print it if ( len(b) ): # print nothing, because length b is 0 (and 0 is evaluated as False) x = x+1 print(b + str(x) ) print( x ) # 11
2nd Apr 2019, 7:14 PM
zemiak