Edit detail for Closures revision 1 of 1

1
Editor: AbdulKaderMaliyakkal
Time: 2007/02/27 12:15:50 GMT+0
Note:

changed:
-
Closure
-------

A closure is a block of code that can be passed as an argument to a function call.Typically, a closure occurs when one function appears entirely within the body of another, and the inner function refers to local variables of the outer function.

    >>> def my_fn(x):
            return lambda y:  x > y     

    Here the variable 'x' lives on beyond the scope of my_fn().

    >>> f = my_fn(10)
    >>> f(10)
    False
    >>> f(9)
    True

Closure

A closure is a block of code that can be passed as an argument to a function call.Typically, a closure occurs when one function appears entirely within the body of another, and the inner function refers to local variables of the outer function.

>>> def my_fn(x):
        return lambda y:  x > y     

Here the variable 'x' lives on beyond the scope of my_fn().

>>> f = my_fn(10)
>>> f(10)
False
>>> f(9)
True