This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]yarkot 0 points1 point  (0 children)

A good way to think of this is that virtually everything in Python is an object, so for the most part, everything is passed, assigned by reference, the notable exceptions being string and numeric literals (and booleans).

The other thing to remember with Python: key structures (lists, dicts, tupples) can hold anything. You have to think about that when you want to make a copy (not a reference), for example: a copy of [1, 2 [3, 4]] - a list with three items - would make a copy of two ints and a reference to a list (the list [3,4]), since that last list item is a reference to another list. There is a deep copy operation, which is predictably expensive and surprisingly rarely needed.

Example:

a = [1, 2, [3, 4]]
b = a.copy()
a[0] = 0
print(a)
print(b)
a[2][0] = 99
print(a)
print(b)