1

code:

funcs = []

for i in xrange(5):

    def func():
        print i, id(func)

    func()
    funcs.append(func)

print

for func in funcs:
    func()

ret:

0 139805502318064
1 139805502318184
2 139805502318304
3 139805502318424
4 139805502318544

4 139805502318064
4 139805502318184
4 139805502318304
4 139805502318424
4 139805502318544

Can I create some functions in for loop and save them?

atupal
  • 16,404
  • 5
  • 31
  • 42

0 Answers0