Join Regular Classroom : Visit ClassroomTech

Python Set – all() Function

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

Syntax:
all(itearable)

Also Read: Python Set – isdisjoint() Method

Example 1:

# Python code to understand all() method in set
# www.codewindow.in

s = {True, True, True}
x = all(s)
print(x)

Output:

True

Explanation:
Here all the items in the set are True. Hence returned True.

Example 2:

# Python code to understand all() method in set
# www.codewindow.in

s = {True, False, True}
x = all(s)
print(x)

Output:

False

Explanation:
Here there is a False in the second position of the set. Therefore all the elements are not True. Hence returned False.

Example 3:

# Python code to understand all() method in set
# www.codewindow.in

s = {0, 1, 1}
x = all(s)
print(x)

Output:

False

Explanation:
Here 0 is considered as false. Therefore the first element is False. Hence returned False.

Example 4:

# Python code to understand all() method in set
# 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.


Follow Us

You Missed

Also Checkout