Join Regular Classroom : Visit ClassroomTech

all() function in Python List

It is a function in list that returns True if all the items in the list are True else returns False. 1 is considered as True and 0 is considered False.

Syntax:

all(itearable)

Don’t know what is len function in Python List? Read: len() function in Python List

Example 1:

# Python program to understand all() function in list
# www.codewindow.in

s = [True, True, True]
x = all(s)
print(x)

Output:

True

Explanation:

Here all the items in the list are True. Hence returned True.

Example 2:

# Python program to understand all() function in list
# www.codewindow.in

s = [True, False, True]
x = all(s)
print(x)

Output:

False

Explanation:

Here all the items in the list are not true, one item is False. Hence returned False.

Example 3:

# Python program to understand all() function in list
# www.codewindow.in

s = [0, 1, 1]
x = all(s)
print(x)

Output:

False

Explanation:

Here 0 is considered as false. Therefore one element is False. Hence returned False.

Example 4:

# Python program to understand all() function in list
# www.codewindow.in

s = [1, 1, 1]
x = all(s)
print(x)

Output:

True

Explanation:

Here all the elements are 1, therefore all are True. Hence returned True.


You Missed

Also Checkout