I am new to python, and more used to C++. I want to create a list of instances and did the following:
from copy import deepcopy
class C:
c1=""
c2=""
Cs=[]
C.c1="Hello"
C.c2="World"
Cs.append(deepcopy(C))
C.c1="Why"
C.c2="this?"
Cs.append(deepcopy(C))
for c in Cs:
print (c.c1, c.c2)
I expected the following output:
Hello World
Why this?
but got:
Why this?
Why this?
Why is the deep copy not working?