Python function-any ()

Source: Internet
Author: User
Any (iterable)


Version: This function is suitable for version 2.5 and above, compatible with Python3 version.


Description: If any element of iterable does not return true for 0, ' ', False,all (iterable). Returns False if Iterable is empty. The function is equivalent to:


Note the difference between the function and the all () function, any is arbitrary, and all is all. It is suggested to compare and learn the difference between the two. You can refer to the Python function for a daily talk-all ()


def any (iterable):

For element in iterable:

If element:

Return False

Return True

Parameter iterable: an iterative object;


Example:



>>> any ([' A ', ' B ', ' C ', ' d ']) #列表list, the elements are not empty or 0

True

>>> any ([' A ', ' B ', ' ', ' d ']) #列表list, there is an empty element

True

>>> any ([0, ', false]) #列表list, the element is all 0, ', false

False

>>> any (' A ', ' B ', ' C ', ' d ') #元组tuple, the elements are not empty or 0

True

>>> any (' A ', ' B ', ' ', ' d ') #元组tuple, there is an empty element

True

>>> any (0, ', false) #元组tuple, element is all 0, ', false

False

>>> any ([]) # Empty list

False

>>> any (()) # Empty tuple

False

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