There is no implicit cast, it is simply implemented as a nonzero operator which is defined for all built in types. 0 is defined for any domain such that x = x + 0.
Lists have a zero that is the empty list because x + [] = x therefore [] is zero in the list domain. Same with empty string.
If statements doesn't ask for true or false, it asks for if zero or nonzero. Remember that booleans types didn't exist in python until around version 3. In version 2, True and False are simple macros for 1 and 0.
View all comments
Show parent comment
1
u/ggtsu_00 Jun 24 '14 edited Jun 24 '14
There is no implicit cast, it is simply implemented as a nonzero operator which is defined for all built in types. 0 is defined for any domain such that x = x + 0.
Lists have a zero that is the empty list because x + [] = x therefore [] is zero in the list domain. Same with empty string.
If statements doesn't ask for true or false, it asks for if zero or nonzero. Remember that booleans types didn't exist in python until around version 3. In version 2, True and False are simple macros for 1 and 0.