- In python, every variable name is a reference
- When a variable is passed to a function, a new reference to the object is created
- If the value passed in a function is immutable, the function does not modify the caller’s variable
- If the value is mutable, the function modify the caller’s variable in-place
def changing_values(x,y,z):
x = 10
y.remove(20)
z=[5,10,15]
print("Inside the function, values of a,b,c are")
print(x)
print(y)
print(z)
a=100
b=[10,20,30]
c=[1000]
print("Before calling the function: values of a,b,c are")
print(a)
print(b)
print(c)
changing_values(a,b,c)
print("After calling the function: values of a,b,c are")
print(a)
print(b)
print(c)
Output:
Before calling the function: values of a,b,c are
100
[10, 20, 30]
[1000]
Inside the function, values of a,b,c are
10
[10, 30]
[5, 10, 15]
After calling the function: values of a,b,c are
100
[10, 30]
[1000]
Views: 2