Python built-in functions (2) -- all, python built-in functions all

Source: Internet
Author: User
Tags iterable

Python built-in functions (2) -- all, python built-in functions all

English document:

all(Iterable)

ReturnTrueIf all elements ofIterableAre true (or if the iterable is empty). Equivalent:

def all(iterable):    for element in iterable:        if not element:            return False    return True

 

Note:

1. Accept an iterator object as a parameter. If the parameter is null or not an iterator object, an error is returned.

>>> All (2) # input value error Traceback (most recent call last): File "<pyshell #9>", line 1, in <module> all (2) typeError: 'int' object is not iterable

2. If the logical value of each element in the iteratable object is True, True is returned; otherwise, False is returned.

>>> All ([1, 2]) # returns TrueTrue if the logical value of each element in the list is True. >>> all ([, 2]) # If the logical value of 0 in the list is False, FalseFalse is returned.

3. If the iteratable object is null (the number of elements is 0), True is returned.

>>> All () # null tuples True >>> all ({}) # null dictionary True

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.