Why print(all([])) returns true?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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!!

20th Nov 2018, 3:25 PM
I'm_Groot
I'm_Groot - avatar
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
20th Nov 2018, 4:10 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 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.
20th Nov 2018, 4:05 PM
Kishalaya Saha
Kishalaya Saha - avatar