How to Use all() Function in PythonPython Basics


The all() function returns True if any element in an iterable is true, otherwise False.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

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

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

Output:

False
True

Syntax

all(object)

Parameters

Name Description
object An iterable object (list, tuple, or dictionary)

Return Value

It returns True or false.

© 2024 Learnwithgpt.org, all rights reserved. Privacy Policy | Contact Us