Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python any() Function

any() is a built-in function in python programming language which gives a True in return if all elements of an iterable are true (exists) and give False if iterable is empty. All sequence types in Python are examples of iterable. Example sequence types in Python:

  1. Lists
  2. String
  3. Tuple

any() function is a part of Python Built-in Functions (check list)

any() Syntax

any( iterable )

 

any() Parameters

iterable – where argument iterable is an iterable or variable representing iterable (Lists , strig, tuple or custom)

 

any() Return Value

any() function returns a true if elements of iterable are true and return false if iterable is empty.

 

any() Compatibility

This function is available and compatible with both Python 2.x and 3.x

Python 2.xPython 3.x
YesYes

 

any() Function Examples

 

When iterable is list (Number) in any()

Example

Output: True

 

When iterable is list (String) in any()

Example

Output: True

 

Empty list iterable in any()

Example

Output: False

 

When iterable is string in any()

Example

Output: True

 

When iterable is tuple (Number) in any()

Example

Output: True

 

When iterable is tuple (string) in any()

Example

Output: True

 

Empty tuple in any()

Example

Output: False

Loading...
LearnAndLearn.com © 2018 - All rights reserved