To avoid accidentally modifying a global variable, python requires an explicit global
statement before assigning to a global variable. However, modifying a global variable by calling its method can be done without any extra statement:
x = [1, 2]
y = [1, 2]
def f():
global x
x = x + [3] # won't affect global variable without global statement
y.append(3) # will affect global variable without global statement
This seemed slightly inconsistent. Is this design choice made because it's considered less dangerous / less of a bad practice to modify global mutable objects through a method call, compared to replacing them with an entire new object? If so, why?