Stop using = operator to create a copy of a Python list. Use copy method instead

Stop using = operator to create a copy of a Python list. Use copy method instead

When you create a copy of a Python list using the = operator, a change in the new list will lead to the change in the old list. It is because both lists point to the same object.

Instead of using = operator, use copy() method. Now your old list will not change when you change your new list. Find an example above.

Link to the source code.

Search

Related Posts

Related Posts

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran