Python all() function returns true if all values of the passed iterable object are true else it returns false.

Basically, all() Function in python checks whether all elements in the list, tuple, dictionary, etc is true or not.

Syntax:

Python all() Parameters

iterable_object – Any iterable which can contain more than one elements e.g list, dictionary, set, tuple, etc

all() in Python returns only true or false depending on the elements.

Python all() Examples

Example 1: List

Any integer except 0 is considered as true in Python.

Example 2: Dictionary

all() check keys instead of values for the dictionary.

Example 3: String

Though 0 in Python means false but '0' in Python is a character which has non-zero ASCII code therefore result into True.

Comment below your suggestion or doubts.

Leave a Reply

Close Menu