Product SiteDocumentation Site

12.4. Clousers

Clousers are nothing function which got returned by another function. We use clousers to remove code duplications. In the following example we create a simple clouser for adding numbers.
>>> def add_number(num):
...     def adder(number):
...         'adder is a clouser'
...         return num + number
...     return adder
... 
>>> a_10 = add_number(10)
>>> a_10(21)
31
>>> a_10(34)
44
>>> a_5 = add_number(5)
>>> a_5(3)
8

*adder* is a clouser which adds a given number to a pre-defined one.