all

Full name
all
Library
Built-in
Syntax

all(iterable)

Description

The all function returns the boolean True if all elements in the iterable passed as an argument are True (or if the iterable is empty), and returns the boolean False otherwise.

This function is equivalent to:

def all(iterable):

    for element in iterable:

        if not element:

            return False

    return True

Parameters
  • iterable: iterable to analyze.
Examples

If, for example, the iterable is a list, the function will return True only if all its elements are True:

All function. Example of use

If, on the contrary, any of its elements take the value False, the function will return False:

All function. Example of use

 

In the case that the iterable values are not boolean, they are interpreted appropriately. Thus, nonzero numbers are interpreted as True, and zeros as False:

All function. Example of use

If they are complex numbers, only the number 0 + 0j is interpreted as False:

All function. Example of use

 

Continuing with the example of the list, if it is empty, the function returns True:

All function. Example of use

 

Submitted by admin on Sat, 01/19/2019 - 23:05