+ 2

What all(code) do in Python?

What this code do? if all(filter(lambda x: x%4==0, num_list)): print('yes') my question is, what all() do here? note that num_list here is a generic list entered by user.

17th Jan 2018, 7:14 PM
Mohamed Saad
Mohamed Saad - avatar
2 Antworten
+ 2
all() is a method that returns True when all elements in the given iterable are true. If not, it returns False. Reference: programiz Hope this helps!!!
17th Jan 2018, 8:13 PM
Dread
Dread - avatar
0
all() function returns true if all elements in the list are true. Basically it's unnecessary because your filter function will return a list that contains only true values. def all(list): for element in list: if not element: return False return True
17th Jan 2018, 8:11 PM
Toni Isotalo
Toni Isotalo - avatar