1 year ago
#379102
Betty
a python question about list, append and mutability
Here is my code:
list1 = ["dog", "cat"]
list2 = list1
list2.append ("fish")
print(list1)
print(list2) # both list1 and list2 will be [“dog”, “cat”, “fish”].
I do understand why print(list1)
>>> [“dog”, “cat”, “fish”]
.
But I do not understand why print(list2)
>>> [“dog”, “cat”, “fish”]
.
Could someone explain it please?
python
list
mutability
0 Answers
Your Answer