4 ms·
I dont understand the difference between a closure and an object's state. Is an object one example of a closure? You can pass it around and it contains instance
by jrvarela56 15y ago
I dont understand the difference between a closure and an object's state. Is an object one example of a closure? You can pass it around and it contains instance variables.
What are lambdas for in this context? Simply calling the object's attribute would return the value set at creation - even if modified afterwards.
- jrvarela56 15y agoHope this helps: (Python) def closure(x): return lambda y:x+y a = closure(5) #'a' is a function now a(2) #returns 7 a(3) #returns 8 The function 'closure' can be carried around and it remembers the value of x from when it was created. Got the example from this article: http://linuxgazette.net/109/pramode.html http://linuxgazette.net/109/pramode.html (I believe it was shared a few weeks ago) - great reference for other FP concepts and a good way to get started in FP if you already like working with Python.