recently I encountered some confusion when I was learning Python
. I don"t know how to understand it for a while, as follows:
use version python3.6
suppose you have the following three pieces of code:
l = [1]
print(id(l))
l = l + [2]
print(id(l))
the above code finds that the address has changed
my understanding is limited to knowing that the list is a mutable object, but the above three pieces of code do not know how to explain the principle. I still feel that there are still some places that do not understand clearly.
I would like to have an answer from my seniors. I would appreciate it