Python function-All ()

Source: Internet
Author: User
All (iterable)

Version: This function appears for the first time in the python2.5 version, and is suitable for 2.5 or more versions, including Python3, compatible with the Python3 version.

Description: If all elements of iterable are not 0, ', false, or iterable null, all (iterable) returns True, otherwise false; The function is equivalent to:

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

Parameter iterable: an iterative object;


Example:

>>> all ([' A ', ' B ', ' C ', ' d '])  #列表list, the elements are not empty or 0true>>> all ([' A ', ' B ', ', ' d '])  #列表list, There is an empty element false>>> all ([0, 3])  #列表list, there is an element of 0 false  >>> all ((' A ', ' B ', ' C ', ' d '))  #元组tuple, the elements are not empty or 0true>>> all ((' A ', ' B ', ', ' d ')  #元组tuple, there is an empty element false>>> all (0, 1, 2, 3))  #元组tuple, there is an element of 0 false    >>> all ([]) # Empty list true>>> All (()) # Empty tuple True


Note: Empty tuple, empty list return value is true, here is to pay special attention to

  • 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.