Skip to content

Instantly share code, notes, and snippets.

@antonioshadji
Last active May 26, 2025 15:33
Show Gist options
  • Save antonioshadji/eb416ce60426e1faac66b89cc211a883 to your computer and use it in GitHub Desktop.
Save antonioshadji/eb416ce60426e1faac66b89cc211a883 to your computer and use it in GitHub Desktop.
test of python default argument definition and the results
def func(x=[]):
x.append(1)
return x
print(func())
print(func())
print(func([2]))
print(func())
# above code show that default parameter is defined exactly once when function in defined
# x the default parameter still exists, but is unused if a parameter is given to the function
# https://img.leroscapital.com/python-default-parameter-definition.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment