Skip to content

Instantly share code, notes, and snippets.

@Gwith
Created August 8, 2016 22:28
Show Gist options
  • Select an option

  • Save Gwith/6f269245893fbc66ca96bd074435ecc4 to your computer and use it in GitHub Desktop.

Select an option

Save Gwith/6f269245893fbc66ca96bd074435ecc4 to your computer and use it in GitHub Desktop.
def append_twice_okay(a_list, val):
"""mutates argument."""
a_list.append(val)
a_list.append(val)
def append_twice_good(a_list, val):
"""returns new list."""
a_list = a_list + [val, val]
return a_list
nums_okay = [1, 2, 3]
append_twice_okay(nums_okay, 7)
print(nums_okay)
nums_good = [1, 2, 3]
append_twice_good(nums_good, 7)
nums_good_new = print(nums_good)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment