-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions_any().py
43 lines (29 loc) · 940 Bytes
/
Functions_any().py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Python any() Function
# Example
# Check if any of the items in a list are True:
mylist = [False, True, False]
x = any(mylist)
# Definition and Usage
# The any() function returns True if any item in an iterable are true, otherwise it returns False.
# If the iterable object is empty, the any() function will return False.
# Syntax
# any(iterable)
# Parameter Values
# Parameter Description
# iterable An iterable object (list, tuple, dictionary)
# More Examples
# Example
# Check if any item in a tuple is True:
mytuple = (0, 1, False)
x = any(mytuple)
# Example
# Check if any item in a set is True:
myset = {0, 1, 0}
x = any(myset)
# Example
# Check if any item in a dictionary is True:
mydict = {0 : "Apple", 1 : "Orange"}
x = any(mydict)
# *Note: When used on a dictionary, the any() function checks if any of the keys are true, not the values.
# Related Pages
# The all() Function