from __future__ import nested_scopes # python 2.1.1 def foo (n): a = lambda: 'you said (%d)' % n n += 3 return a x = foo(1) print x() This prints 4, rather than 1 as I would have expected. I think I understand what's going on, but is it really what was intended? Is there a preferred way of writing this kind of function? Thanks.