I wonder if any python folks can fill me in on how/why the following happens:
# define a list and send it as an arg to another function
def foo():
nums=[1,2,3]
bar(nums)
print(nums)
# Take the list as an arg and pop the last element off
def bar(numbrs):
numbrs.pop()
# Call the first function
foo()
# The nums local variable has been modified
[1, 2]
As a rubyist I find it really strange that a locally defined variable (nums) in the foo function can be changed by an action performed in the bar function! Is this kind of entanglement normal? Is there a name for it?
The two functions don't even use the same name to refer to the list. It's very peculiar. I kind of like it though.