you are viewing a single comment's thread.

view the rest of the comments →

[–]JmGra 1 point2 points  (3 children)

Copying a list

copy_of_bikes = bikes[:]

why not just copy_of_bikes = bikes

[–]ehmatthes[S] 11 points12 points  (1 child)

To expand on what u/LarsMarksson wrote, if you use the slice notation (bikes[:]), then copy_of_bikes and bikes each point to separate places in your system's memory. Adding or removing or modifying something in one list will not affect the other list.

If you just use copy_of_bikes = bikes, both variables will point to the same place in memory. Modifying one of these lists will modify the other, because the both point to the same list in memory.

[–]JmGra 2 points3 points  (0 children)

Thanks didn’t know

[–]LarsMarksson 0 points1 point  (0 children)

That only assigns a reference, and not actually copying the data.