From the docs, all
is equivalent to:
def all(iterable):
for element in iterable:
if not element:
return False
return True
Then why do I get this output:
# expecting: False
$ python -c "print( all( (isinstance('foo', int), int('foo')) ) )"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'foo'
When:
# expecting: False
$ python -c "print( isinstance('foo', int) )"
False
One (fairly ugly) way to get the behaviour you want is via lambdas:
all(f() for f in (lambda: isinstance('foo', int), lambda: int('foo')))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With