I understand that if I pass a variable as an argument to a function it can only change the value of that argument within its own scope, not the value of the variable at the global scope.
However, this doesn't seem to apply to passing user-defined class instances to a function, where I am able to modify that object in the global scope without a return statement in the function.
For example, in the code below I would have expected the function bar() to only modify the values within the scope of the function, and not change the 'my_class_object' instance of foo in the global scope. However, when I run bar() I find that the value of my_class_object.the_value changes from 0 to 1.
class foo():
def __init__(self,num):
self.the_value = num
def bar(a,b):
a.the_value +=1
b +=1
my_class_object = foo(0)
int_class_object = 0
bar(my_class_object,int_class_object)
print(my_class_object.the_value)
print(int_class_object)