Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Closure function
#1
Closure function doesn't make sense:
def make_multiplier_of(n):
    def multiplier(x):
         return x * n
    return multiplier
times3 = make_multiplier_of(3) 
times5 = make_multiplier_of(5)
Can anybody explain the implementation detail how python can know a function is a closure function and don't delete the enclosing function's name and their value after the enclosing function return ? And where that value is stored ? I didn't even call the multiplier function in the make_multiplier_of function, so how python can go to the body code and know that is a closure function and retain the required information ?
Reply


Messages In This Thread
Closure function - by Uchikago - Jul-11-2019, 09:06 AM
RE: Closure function - by Gribouillis - Jul-11-2019, 10:21 AM
RE: Closure function - by Uchikago - Jul-11-2019, 10:36 AM
RE: Closure function - by Gribouillis - Jul-11-2019, 11:03 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020