1class Test:
2 a = 1
3
4def f(obj):
5 obj.a = 10
6
7t = Test()
8f(t)
9
10# t.a should be 10
1# objects are passed by reference, but
2# its references are passed by value
3
4myList = ['foo', 'bar']
5
6def modifyList(l):
7 l.append('qux') # modifies the reference
8 l = ['spam', 'eggs'] # replaces the reference
9 l.append('lol') # modifies the new reference
10
11modifiyList(myList)
12
13print(myList) # ['foo', 'bar', 'qux']
1# primitive types are passed by value
2# objects are passed by reference
3# https://www.geeksforgeeks.org/is-python-call-by-reference-or-call-by-value/