Skip to content

Instantly share code, notes, and snippets.

@Gwith
Created August 8, 2016 23:00
Show Gist options
  • Select an option

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

Select an option

Save Gwith/9cbd49c652758cc851f06c7593d7ea01 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