3 ms·
so if I did this (following from your example): n = 35 a = foo(n) a() n = 42 a() I would get 35 printed both times, despite n having changed. is tha
by Tycho 16y ago
so if I did this (following from your example):
n = 35
a = foo(n)
a()
n = 42
a()
I would get 35 printed both times, despite n having changed. is that the idea?
- falcolas 16y agoLanguage specifics mean that this might not always be the case. i.e. >>> s = "%03d" >>> f = lambda x: s % x # Identical behavior for a regular function closure >>> map(f, range(10)) ['000', '001', '002', '003', '004', '005', '006', '007', '008', '009'] >>> s = "%04d" >>> map(f, range(10)) ['0000', '0001', '0002', '0003', '0004', '0005', '0006', '0007', '0008', '0009'] I would try and think of it as more of a function parameter that you pre-fill, and never have to provide again for that instance of the function.