Created
June 29, 2014 11:11
-
-
Save pradeepvairamani/420be35fe0b8118a63eb to your computer and use it in GitHub Desktop.
Tumblr: Mutability 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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