python send object reference to another function and edit property
class Test:
a = 1
def f(obj):
obj.a = 10
t = Test()
f(t)
# t.a should be 10
python send object reference to another function and edit property
class Test:
a = 1
def f(obj):
obj.a = 10
t = Test()
f(t)
# t.a should be 10
python pass by reference
# objects are passed by reference, but
# its references are passed by value
myList = ['foo', 'bar']
def modifyList(l):
l.append('qux') # modifies the reference
l = ['spam', 'eggs'] # replaces the reference
l.append('lol') # modifies the new reference
modifiyList(myList)
print(myList) # ['foo', 'bar', 'qux']
does python pass by reference
# primitive types are passed by value
# objects are passed by reference
# https://www.geeksforgeeks.org/is-python-call-by-reference-or-call-by-value/
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us