Python function-any ()

Source: Internet
Author: User

Any (iterable)

Role:

If any element of iterable is not 0, ' ', False,all (iterable) returns True. Returns False if Iterable is empty.

The function is equivalent to:

1 def Any (iterable): 2     for inch iterable: 3        if   element:4            return False 5    return True

Parameter iterable: an iterative object;

Instance:

1>>> any (['a','b','C','D'])#list, elements are not empty or 02 True3>>> any (['a','b',"','D'])#List of lists, there is an empty element4 True5>>> any ([0,"', False])#list, elements are all 0, ', False6 False7  8>>> any ('a','b','C','D'))#tuples tuple, elements are not empty or 09 TrueTen>>> any ('a','b',"','D'))#tuples tuple, there is an empty element One True A>>> any (0,"', False))#tuples tuple, element all 0, ', False - False -   the   ->>> any ([])#Empty list - False ->>> any (())#Empty tuple +False

Attention:

Compare the function with the all () function, any is arbitrary , and all is all . Suggest the difference between learning and the relationship between the two

Python function-any ()

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.