Sorry if the title is not accurate, not sure how to name it properly. the question is. If I do this code:
num = 1
def test_func2(arg):
arg = 10
test_func2(num)
print(num)
The num will obviously stay 1 But if I do similar thing with objects
class TestClass:
def __init__(self):
self.one = 1
self.two = 2
test_obj = TestClass()
def test_func(arg):
arg.one = 10
test_func(test_obj)
print(test_obj.one)
The value of test_obj.one will change to 10. Why are integers passed by value and user defined objects by reference?