Python any()

The any() function returns True if any item in an iterable are true. If no item is true then False.

Syntax & Parameters

any(iterable)

iterable – An iterable object list, tuple, dictionary etc.

Ex.

# 1 is True , 0 is False 
mList = [1, 1, 0]
print(any(mList))

# The any() function checks the keys, not the values in dictionaries.
mDict = {0 : "Car", 1 : "Truck"}
print(any(mDict))

# True  
mStr = "this is a string"
print(any(mStr))

Output :

True
True
True

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s