What is passing by reference?

Passing by reference means: if a variable is passed to a function and altered, the original variable is changed also. That is, passing a variable does not create a local copy of it. All parameters in Python are passed by reference.

#example
original = [1,2,3,4,5]

def addSix(lst):
 "Adds a 6 to lst"
 lst.append(6);
 return

addSix(original)
print(original)

#output
[1, 2, 3, 4, 5, 6]
Advertisements