Debajyoti KarFront End Web Development Techdegree Student 2,244 Points
couldn't we have just equated the two variables instead of using .copy?
I understand the purpose might have been just to share the existence of such method. But instead of using
- items = wishes.copy() could he not have just done
- items = wishes
is there any specific case where using .copy method might be more advantageous over simply equating the two variable? Or it doesn't matter and either would work.
Steven Parker176,806 Points
As Philip explained, a simple assignment causes the new variable to point to the same list. So if you then add another item to "wishes", when you examine "items" it will be there also! To make them independent requires a copy.
The other question Philip linked to has a discussion about equality vs. identity that you may also find helpful.