I am new to python and trying to understand how lists and functions work. When I invoke the first function, it does not change the value of the variable b
. Shouldn't this function change the value of the variable b
rather than just returning the modified value when using print statement. On the other hand, after the second function is invoked, the value of the variable b
is completely changed. What is the difference between these to function's effect on the variable?
b = [1,2,3,4]
def func(a):
a = a[2:3]
return a
print(func(b))
print(b) #Although the func is invoked the value of the variable is unchanged
def newFunc(t):
t.append(5)
newFunc(b)
print(b)