Can please someone explain why the the following operations have not equal outcome when passed to a function?
lis=lis+[1]
lis+=[1]
Shouldn't that be the same?
The problem derives from the following code:
def f1(lis):
lis=lis+[1]
print(id(lis))
list1=[0]
print("before function", id(list1))
f1(list1)
print("after function", id(list1))
print(list1)
before function 45004000
45004160
after function 45004000
[0]
Why is "1" not added to list1
like it does below?
def f1(lis):
lis+=[1]
print(id(lis))
list1=[0]
print("before function", id(list1))
f1(list1)
print("after function", id(list1))
print(list1)
before function 45200888
45200888
after function 45200888
[0, 1]