Much has been written about python pass-by-object-reference. But it is confusing to read threads like this or this.
In those threads, some say mutability is important, while others say that mutable or immutable objects are handled the same way.
I have a simple question, why are the contents of a
not modified in the first snippet of code and modified in the second? According to this explanation of pass-by-object-reference, shouldn't the contents of the reference be modified in both cases?
def fn(b):
b += 1
a = 2
fn(a)
print(a)
def fn(b):
b += [4]
a = [2]
fn(a)
print(a)