« first day (692 days earlier)      last day (2886 days later) » 

14:57
def f(s1):
    def g(n, s=s1):
        return s1 * n
    return g

h = f('a')
print([h(i) for i in (1,2,3)])
h = f('b')
print([h(i) for i in (4,5,6)])
#output
['a', 'aa', 'aaa']
['bbbb', 'bbbbb', 'bbbbbb']
Here's what dis(f) prints:
 32           0 LOAD_DEREF               0 (s1)
              3 LOAD_CLOSURE             0 (s1)
              6 BUILD_TUPLE              1
              9 LOAD_CONST               1 (<code object g at 0xb71b7ac0, file "./qtest.py", line 32>)
             12 LOAD_CONST               2 ('f.<locals>.g')
             15 MAKE_CLOSURE             1
             18 STORE_FAST               1 (g)

 34          21 LOAD_FAST                1 (g)
             24 RETURN_VALUE
3 messages moved from Python

« first day (692 days earlier)      last day (2886 days later) »