list1 has 'a' because the list created with extendlist('a') is added to the same list as extendList(10)
This is, without a doubt, the result of detail in how Python deals with default arguments and the state model. You can even claim that this is a mistake because it violates the closure property (if it is assumed that the Python methods are closures).
For example, equivalent code in Ruby:
def extendList(val, list=[]) list << val return list end
returns
extendList(10)
This is in Ruby, because Ruby methods are closures, i.e. Each method call carries a local environment around it.
source share