@ 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.
I've tried.
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)
result
Success time: 0 memory: 23304 signal:0
7of9 is my decoy
Tuvok is my decoy
Janeway is my decoy
You will learn how to use Closure soon.
https://en.wikipedia.org/wiki/Political_decoy
Recommended Posts