I'm trying to understand why int("0") > 0
evaluates to false
while all([int(i) > 0 for i in "0"])
evaluates to true
. Interestingly, [all(i != "0" for i in "0"]
also evaluates to true
.
How can I get my list comprehension to evaluate correctly, that is, catch the "0"?
int
is being called with different types, because iterating over a string is givingChar
objects, not strings of length 1:and when given a
Char
, Julia'sint
is more like Python'sord
:which gives rise to what you see:
There are lots of ways you could get this to behave as you expect, e.g. use
parseint
or simply convert back to a string: