I am new to python. I searched a lot but couldn't find the reason why this is happening. Could anyone please tell me the difference between these two?
My general question is when using a list in function is by reference and when is by value?
My test
function is acting as call by reference and test2
is acting as call by value.
I know in python everything is an object, but with that, I couldn't understand the difference. tnx
def test(my_list):
for i in range(len(my_list)):
my_list[i] = 5
def test2(my_list1):
my_list1 = [6, 6, 6]
a = [4, 4, 4]
print(a)
test(a)
print(a)
test2(a)
print(a)
output:
[4, 4, 4]
[5, 5, 5]
[5, 5, 5]