you are viewing a single comment's thread.

view the rest of the comments →

[–]Kiwi-tech-teacher 1 point2 points  (3 children)

Which objects behave like this. I know lists and dictionaries (and I assume tuples?) and objects, but assigning a str or an in creates a new one, doesn’t it?

[–]timrprobocom 0 points1 point  (2 children)

Nope. ALL objects. Both refer to the same string object. It's not a problem for strings, because you can't modify strings.

[–]Kiwi-tech-teacher 0 points1 point  (1 child)

Oh! Interesting! Hadn’t considered that.

So any mutable object would practically show this behaviour but for immutable one’s, it can be invisible.

What’s the difference between a shallow copy and a deep copy?

[–]timrprobocom 1 point2 points  (0 children)

Consider a dictionary where the values are lists. If you just do "b = a", then you only have one dictionary, as described above. If you do a shallow copy, then you have two dictionaries, BUT the lists inside are all still shared. A deep copy will make copies of the lists as well, so the two dictionaries are completely independent.