Understanding Mutable Default Arguments in Python


Avoid using mutable default arguments to prevent unexpected behavior.

Source Code

def append_to(element, to=None):
    if to is None:
        to = []
    to.append(element)
    return to
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments