def f(value,values):
value = 4
values[0] = 100
t = 1
v = [1,2,3]
f(t,v)
print(t,v[0])
let start walking through you code, you are defining a function f:
def f(value,values):
value = 4
values[0] = 100
this function takes 2 parameter value
and values
, ok now move to the code after function
t = 1 # here you are declaring a variable name 't' and have value 1
v = [1,2,3] # here we have 'v' having value [1,2,3] which is a list
f(t,v) # here you are calling the function 'f' which is declare above
Ok, now our main work start when you are calling function 'f' f(t,v)
with two parameter having value t=1
& v=[1,2,3]
when these parameter reaches our function f(value,values)
we have value = 1
and values = [1,2,3]
.
after that, we have value=4
inside our function so as we have value = 1
previously then our code will like :
value=4 # previously we have value = 1 so now our code update the value to 4, t does not updated here.
after that we have values[0]=100
so we have values as [1,2,3] this becomes like:
values[0]=100 # => [1,2,3][0] = 100 so the array [1,2,3] have 1 on index 0 it will replace 1 in array and now our array becomes [100,2,3]
when we do print(t,v[0])
we have t=1
and v[0]=100
because we didn't update the value of t inside our function only the value of our array [1,2,3]
get update to [100,2,3]