Consider the following code:
def test(Tlist):
Tlist.sort(reverse=True)
Tlist=[0.02,0.1,4,35]
print(Tlist)# [0.02, 0.1, 4, 35]
test(Tlist)
print(Tlist)# [35, 4, 0.1, 0.02]
def test2(a):
a+=1
a=0
print(a)# 0
test2(a)
print(a)# 0
What confuses me is that in the first function test, the list Tlist is being modified. But in the function test2, the variable a is not.
But conceptually both are sent as parameters to my functions. I don't understand why the list is being modified ? I thought that sending a variable to a parameter of a function would have for effect that this variable is not changed globally within the function.