+ 4
Why print(all([])) returns true??
The working principle of all() is that it returns true only if all the elements of the iterable is true ??Isn't it!! Then why its returning True for a empty list đŁI'm lost here Please help!!
2 Answers
+ 13
def all(iterable):
for i in iterable:
if not i:
return False
return True
all() is something like this so it skips for loop if iterable is empty and returns True
You can read it's source here: https://github.com/JUMP_LINK__&&__python__&&__JUMP_LINK/cpython/blob/master/Python/bltinmodule.c
+ 9
Hi! You can check out this discussion:
https://www.sololearn.com/Discuss/1397340/?ref=app
If you still have questions, I'd be happy to assist you further.