#!/bin/env python # Default arguments are evaluated just once and in a static scope # To avoid sharing of the default value between subsequent calls, a local definition for a non-existing arg can be used: def f(a, L=None): if L is None: L = [] L.append(a) return L print (f(1)) print (f(2)) # this will print # [1] # [2]