0
def f1(thing: list) -> None:
   thing += ['x', 1]
def f2(thing: list) -> None:
   thing = thing + ['x', 1]

phone = [9]
f2(phone)
print(phone)
f1(phone)
print(f2)

The outputs are [9] for the first print statement and [9, 'x', 1] for the second one. Can anybody explain this occurrence?

adil.a
  • 9
  • 4
  • This two operators calls two different methods one edit current object and the other make new object, we usually use this operators for numbers so we doesn't notice that thing but with list it get the chance to work different. – Kevin Omar Jan 10 '20 at 08:14
  • 1
    Thank you @Selcuk – adil.a Jan 10 '20 at 18:29

0 Answers0