I\'m trying to understand Python\'s approach to variable scope. In this example, why is f() able to alter the value of x, as perceived within
f()
x
It´s because a list is a mutable object. You´re not setting x to the value of [0,1,2,3], you´re defining a label to the object [0,1,2,3].
You should declare your function f() like this:
def f(n, x=None): if x is None: x = [] ...