Created
January 29, 2019 13:35
-
-
Save navenduagarwal/4178029d5e4c5de28362a7012fba3715 to your computer and use it in GitHub Desktop.
Test for python mutability
credits- sentdex
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 = 1 | |
def test(): | |
x = 2 | |
test() | |
print(x) | |
x = 1 | |
def test(): | |
global x | |
x = 2 | |
test() | |
print(x) | |
x = [1] | |
def test(): | |
x = [2] | |
test() | |
print(x) | |
x = [1] | |
def test(): | |
global x | |
x = [2] | |
test() | |
print(x) | |
x = [1] | |
def test(): | |
x[0] = 2 | |
test() | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment