constant

class iteration_utilities.constant(item, /)

Class that always returns a constant value when called.

Parameters:

item : any type

The item that should be returned when called.

Examples

Creating constant instances:

>>> from iteration_utilities import constant
>>> five = constant(5)
>>> five()
5
>>> ten = constant(10)
>>> # Any parameters are ignored
>>> ten(5, give_me=100)
10

There are already three predefined instances:

For example:

>>> from iteration_utilities import return_True, return_False, return_None
>>> return_True()
True
>>> return_False()
False
>>> return_None()
>>> return_None() is None
True
__call__(*args, **kwargs)

Returns item given when creating the instance.

item

(any type) The value that is returned each time the instance is called (readonly).

New in version 0.6.