by mharig · 2y ago · 0 comments
Isn't that exactly what GP said? And gave an example how to create that effect explicitly in functional languages, using refs?
About the scope: Python knows in principal only 2 scopes: local and global. If you define a function (or a class) Python creates a new emtpy/filled with the function arguments local scope (system table). That gets filled successively by local variable assignments etc. There happens a little bit of magic: if you use a variable of the next higher scope, it gets copied (!) to the local scope. You can follow that easily by print(locals()). (You can also use the global scope, but that is another topic).
Edit: had to clarify some points