Last active
December 9, 2017 18:54
-
-
Save DimasInchidi/32794519b41c3f819d117d7d7e17711d to your computer and use it in GitHub Desktop.
why e.C changed after e.get_md() called?
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
from pprint import pprint | |
class E: | |
R = [1, 2, 3, 4] | |
C = [] | |
D = [] | |
def get_mc(self): | |
self.C = self.R | |
for i in range(len(self.R)): | |
self.C[i] = 1 | |
def get_md(self): | |
self.D = self.R | |
for i in range(len(self.R)): | |
print(self.C) | |
self.D[i] = 3 | |
e = E() | |
e.get_mc() | |
pprint(e.C) | |
pprint(e.D) | |
e.get_md() | |
pprint(e.C) | |
pprint(e.D) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment