Join Regular Classroom : Visit ClassroomTech

Python Tuple – all() Method

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

Syntax:

all(itearable)

Don’t know what is sum method in Python Tuple? Read: Python Tuple – sum() Method

Example:

# Python program to understand all() method in tuple
# www.codewindow.in
s = (True, True, True)
x = all(s)
print(x)

Output:

True

Explanation:

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

Example 2:

# Python program to understand all() method in tuple
# 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 tuple. Therefore all the elements are not True. Hence returned False.

Example 3:

# Python program to understand all() method in tuple
# 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() method in tuple
# 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