Python all() Function
Returns True
if all items in an iterable object (a list, tuple, or dictionary)
are True
.
Syntax
Python
Copy Code
all(iterable)
Parameters
Parameter | Description |
---|---|
iterable |
Required. The iterable whose items are to be tested |
Example
Python
Copy Code
allTrue = all([1, True, 'Apples']) print(f'1, True, and "Apples" are all true: {allTrue}') allTrue = all([1, True, 0]) print(f'1, True, and 0 are all true: {allTrue}') allTrue = all([True, False]) print(f'True and False are all true: {allTrue}') allTrue = all({'theSkyIsBlue': True, 'theSunIsYellow' : True}) print(f'All items in the dictionary are true: {allTrue}') allTrue = all((True, 1 > 0)) print(f'All items in the tuple are true: {allTrue}')
Output
1, True, and "Apples" are all true: True 1, True, and 0 are all true: False True and False are all true: False All items in the dictionary are true: True All items in the tuple are true: True