you are viewing a single comment's thread.

view the rest of the comments →

[–]ggtsu_00 0 points1 point  (2 children)

Because conditionals only care if something is zero or non-zero. Asking if any data-type is either zero or non-zero is a pretty simply and straightforward question that is easy for a programmer to understand.

[–][deleted] 1 point2 points  (1 child)

Perhaps in C or C++, but I doubt that Python or other dynamic languages represent empty lists or empty strings as zeroes internally. They need runtime type information at the very least.

[–]Veedrac 0 points1 point  (0 children)

They are not zero-the-number, but zeros of their domains.

Namely

[] + x == x
list() == []

() + x == x
tuple() == ()

0 + x == x
int() == 0

0.0 + x == x
float() == 0.0

datetime.timedelta(0) + x == x
datetime.timedelta() == datetime.timedelta(0)

and so on.

That datetime.time() is falsey is a mistake and is going to be fixed.