Skip to content

Instantly share code, notes, and snippets.

@Gwith
Created August 9, 2016 15:49
Show Gist options
  • Select an option

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

Select an option

Save Gwith/a40bbf726a76b9dd8e1c5c387683e099 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."""
return a_list + [val, val]
nums_okay = [1, 2, 3]
append_twice_okay(nums_okay, 7)
print(nums_okay)
nums_good = [1, 2, 3]
new_list = append_twice_good(nums_good, 7)
print(new_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment