Python built-in function (--any)

Source: Internet
Author: User
Tags iterable

English documents:

any(iterable)

Return True If any element of the iterable is true. If the iterable is empty, return False . Equivalent to:

def any (iterable): As    element in iterable:        if element:            return True    return False

An element that determines whether an element of an object can be iterated with a true value

Description

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

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

2. Returns true if the logical value of one of the elements in an iteration object is true, false when all values are false

>>> any ([0,1,2]) #列表元素有一个为True, returns the Truetrue>>> any ([0,0]) #列表元素全部为False, then returns Falsefalse

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

Python built-in 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.