December 2018
Beginner to intermediate
796 pages
19h 54m
English
This is the final point, and it's very important because Python apparently behaves differently with mutables (just apparently, though). Let's look at an example:
# key.points.mutable.pyx = [1, 2, 3]def func(x): x[1] = 42 # this affects the caller!func(x)print(x) # prints: [1, 42, 3]
Wow, we actually changed the original object! If you think about it, there is nothing weird in this behavior. The x name in the function is set to point to the caller object by the function call and within the body of the function, we're not changing x, in that we're not changing its reference, or, in other words, we are not changing the object x is pointing to. We're accessing that object's element at position 1, and changing ...
Read now
Unlock full access