0
can't understand what's happening in output pls help. is 0 being taken as false and not 0 as true . So as 3 is true but not not
if 0: print("yes") if not 0: print("lol") if 3: print("yes") if not 3: print("lol") output- lol yes
3 Réponses
+ 2
Its better understand that "if" statement want an boolean value else python have to convert it to boolean. Then, the problem, is understand as python convert types to boolean. Well:
- All numeric values will be converted to true except 0
- All class objects will be converted to true except when you define custom __bool__ operator
- None is always converted to false
- Strings are converted to true if are not empty strings, else false
+ 5
0 has always a boolean value of false
every other number returns true - nums included
+ 3
Mostly program languages do it like Mbrustler said. A think you are confuse because in SHELL you have 0 as exit_success and non-zero means exit_failure, in other words, it's backwards.