Skip to content

Instantly share code, notes, and snippets.

@pradeepvairamani
Created June 29, 2014 11:11
Show Gist options
  • Save pradeepvairamani/420be35fe0b8118a63eb to your computer and use it in GitHub Desktop.
Save pradeepvairamani/420be35fe0b8118a63eb to your computer and use it in GitHub Desktop.
Tumblr: Mutability 2
x = 'foo'
y = x
print x # foo
y += 'bar'
print x # foo
x = [1, 2, 3]
y = x
print x # [1, 2, 3]
y += [3, 2, 1]
print x # [1, 2, 3, 3, 2, 1]
def func(val):
val += 'bar'
x = 'foo'
print x # foo
func(x)
print x # foo
def func(val):
val += [3, 2, 1]
x = [1, 2, 3]
print x # [1, 2, 3]
func(x)
print x # [1, 2, 3, 3, 2, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment