# Mutable Default Parameter This [[Anti-Pattern|anti-pattern]] happens when someone wants to [[Definition|define]] a default value to a [[parameter]]. In [[Python]], functions definitions including default values are done when the module is loaded. The default value is stored internally, then used whenever needed, as is. ```python # Don't def spam(bacon=[]): bacon.append("Eggs") return bacon # Do def spam(bacon=None): if bacon is None: bacon = [] bacon.append("Eggs") return bacon ``` Use a mutable default parameter can indeed be used as a way of creating a cache that will be reused between calls but it is often prefered to used global values or an [[OOP - Object Oriented Programming|OOP]] approach to store this state as a class or object state. --- Bibliography: - [Title - website.com](need bibliography)