@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2694 / 12833)
Closure
This is a function that is dynamically generated by another function and can both change and remember the values of variables that were created outside the function.
J'ai essayé.
http://ideone.com/ehuo2k
def define_closure(member):
def Kagemusha():
return "%s is my decoy" % member
return Kagemusha
aKgms = define_closure("7of9")
bKgms = define_closure("Tuvok")
cKgms = define_closure("Janeway")
whoIsKagemusha = aKgms()
print(whoIsKagemusha)
whoIsKagemusha = bKgms()
print(whoIsKagemusha)
whoIsKagemusha = cKgms()
print(whoIsKagemusha)
résultat
Success time: 0 memory: 23304 signal:0
7of9 is my decoy
Tuvok is my decoy
Janeway is my decoy
Vous apprendrez bientôt à utiliser Closure.
https://en.wikipedia.org/wiki/Political_decoy
Recommended Posts