How to Use any() Function in PythonPython Basics


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

Example

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

print(any(['a', 'b', '', 'd']))    # list
print(any([0, '', False]))         # list
print(any((1,2,3)))                # Tuple :(1,2,3)
print(any(()))                     # Empty tuple

Output:

True
False
True
False

Syntax

any(object)

Parameters

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

Return Value

It returns True or False.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us