+ 6
Get confused with if
if 3: print("hi") else: print("no") why if + any number except 0 always True I know that 0 = False , 1 = True but why the other numbers are true??
9 Respuestas
+ 3
Hello! This is a good question.
In fact, this is defined in Python itself. Maybe other languages treat this differently.
See how it happens here:
https://docs.python.org/3/library/stdtypes.html#truth
+ 16
every number except 0 is a true
and every string containing characters is true
+ 16
every number except 0 is a true
and every string containing characters is true
+ 5
but why?
I think there must be a reason for that 😅
+ 4
When you convert ant integer to boolean, it is always true unless it is 0.
+ 1
because earlier in C there wasn't type called boolean, so the represantation: 0 for false and {1,2,3,...} all for true, but now we can use the two terms true and false as a builting type in python(remember python based from C)
+ 1
Yea earlier there was no type called boolean so its representation was 0
0
the secret key for understand the Python is "Python based from C"
0
and if you want to know the ansewrs of most questions related to this language features you should take a quick review to the C basics, thank you for your attention.