Passing objects to functions

When passing objects to functions, only the reference is copied, not the object itself. If the method has access to attributes of the object, it can change the object. This change is preserved after the method returns.

Example

class Person:
    name = ""


def setName(n, o):
    o.name = n


p1 = Person()
p2 = Person()

setName("John", p1)
setName("Tom", p2)
print(p1.name)
print(p2.name)
Output
John
Tom