The Python Game Book

code games. learn Python.

User Tools

Site Tools


Sidebar

Github:

en:glossary:a:any

any

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

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

any() is part of python's built-in functions

Use any() instead of an expression with a lot of or operators:

# instead of:
coordinate_is_invalid = (x < 0) or (y < 0) or (x > 10) or (y >10)
# use any():
coordinate_is_invalid = any([x<0,y<0, x>10, y>10])
</code>

en/glossary/a/any.txt · Last modified: 2020/05/13 10:36 by horst