Python built-in all function detailed description

Source: Internet
Author: User

English documents:

all(iterable)

Return True If all elements of the iterable be True (or if the iterable is empty). Equivalent to:

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

Description

1. Accept an iterator object as a parameter when the argument is empty or not an iterator object is an error

>>> All (2) #传入数值报错Traceback (recent):  File ' <pyshell#9> ', line 1, in <module>
  
   all (2) TypeError: ' int ' object is not iterable
  

2. Returns true if the logical value of each element in an iterator object is true, otherwise false

>>> all ([truetrue>>>]) #列表中每个元素逻辑值均为True, return to all ([0,1,2]) #列表中0的逻辑值为False, return Falsefalse

3. Returns true if an iterator object is empty (number of elements is 0)

>>> All (()) #空元组True >>> all ({}) #空字典True

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.