Python function-any ()

Source: Internet
Author: User
Python function-any () any (iterable)


Version: This function is applicable to Python 2.5 and later versions. it is compatible with Python 3.


Note: If no iterable element is 0, '', False, all (iterable), True is returned. If iterable is null, False is returned. Functions are equivalent:


Note that the difference between this function and all () is that any is arbitrary, and all is all. We recommend that you compare and learn the differences and relationships between the two. For details, refer to "python functions daily lecture-all ()".


Def any (iterable ):

For element in iterable:

If element:

Return False

Return True

Iterable: iteratable object;


Example:



>>> Any (['A', 'B', 'C', 'D']) # list, all elements are not empty or 0

True

>>> Any (['A', 'B', '', 'D']) # list, with an empty element

True

>>> Any ([0, '', False]) # list. all elements are 0,'', and false.

False

>>> Any ('A', 'B', 'C', 'D') # tuple, the elements are not empty or 0

True

>>> Any ('A', 'B', '', 'd) # tuple, an empty element

True

>>> Any (0, '', False) # tuple, all elements are 0,'', false

False

>>> Any ([]) # Empty list

False

>>> Any () # empty tuples

False

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.