In python, is there a difference between calling clear() and assigning {} to a dictionary? If yes, what is it? Example:
clear()
{}
d = {\"stuff\":\"
Mutating methods are always useful if the original object is not in scope:
def fun(d): d.clear() d["b"] = 2 d={"a": 2} fun(d) d # {'b': 2}
Re-assigning the dictionary would create a new object and wouldn't modify the original one.