Tuesday, 20 August 2013

Python: Why does a a lambda define the variable in an inline if?

Python: Why does a a lambda define the variable in an inline if?

Toying around with lambdas in Python I discovered that the following code
is legal in Python 2.7.3 and returns the lambda:
x = lambda: 1 if x else 2
Why does the lambda define x when used in this way?

No comments:

Post a Comment