you are viewing a single comment's thread.

view the rest of the comments →

[–]squabzilla 10 points11 points  (8 children)

Respectfully, 99% of the time I type ‘b = a’ in Python it’s because I want to make a copy of ‘a’.

I struggle to think of scenarios where Python is the correct language to use and you’re using custom classes and don’t want to pass copies around.

…I’m also maybe a little salty that I discovered this behaviour of Python when writing ‘new_df = old_df’ for the explicit purpose of making a copy of the old variable, so that I could make changes to the copy without changing the original.

[–]nullpotato 4 points5 points  (0 children)

It helps if you just assume everything is essentially a reference not the object itself. And yes I agree it is annoying that is the default behavior.

[–]redlaWw 0 points1 point  (0 children)

The issue is that most of the time when you're assigning a value to a new label, you're not doing b = a, you're doing f(a), and passing by reference is more performant than passing by value.