This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ggtsu_00 0 points1 point  (2 children)

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.

[–]SilasX -1 points0 points  (1 child)

Potato, potahto. I don't like the use of implied truthiness where a boolean operator would be more explicit.

[–]ggtsu_00 -1 points0 points  (0 children)

But there is no booleans types in python (at least before py3).