Skip to content

Instantly share code, notes, and snippets.

@agalera
Last active August 29, 2015 14:13
Show Gist options
  • Save agalera/aa10199ba96d0d4009c6 to your computer and use it in GitHub Desktop.
Save agalera/aa10199ba96d0d4009c6 to your computer and use it in GitHub Desktop.
default values in python
#default values in ruby https://gist.github.com/kianxineki/8b13ebc8816623f4a650
def append_values(new_value, a=[]):
a.append(new_value)
return a
append_values("n1") # result ['n1']
rlist = append_values("n2") # result ['n1', 'n2']
rlist.append("n3")
print(rlist) # result ['n1', 'n2', 'n3']
append_values("n4") # result ['n1', 'n2', 'n3', 'n4']
append_values("n0", []) # result ['n0']
append_values("n5") # result ['n1', 'n2', 'n3', 'n5']
append_values.func_defaults # (['n1', 'n2', 'n3', 'n5'],)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment