pythonfunctional-programmingreturn

Python function that always return the same boolean value


In functional programming is sometimes useful to have a function that always return True (or False) for every parameter (or even multiple parameters).

Is there a built-in or a function defined in some module that have this exact behaviour?


Solution

  • I'm not aware of any built-in, but you can define them as:

    false = lambda *_: False
    true  = lambda *_: True