Skip to content

Instantly share code, notes, and snippets.

@DimasInchidi
Last active December 9, 2017 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DimasInchidi/32794519b41c3f819d117d7d7e17711d to your computer and use it in GitHub Desktop.
Save DimasInchidi/32794519b41c3f819d117d7d7e17711d to your computer and use it in GitHub Desktop.
why e.C changed after e.get_md() called?
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