How to keep a unique data for all the classes/instances using it?
This question already has an answer here:
Great thanks for BartoszKP pointed out that data set defined in Python class behaves like static in other language. I used the code below to verify this:
class TwoDimList:
_Val = [ [ i for i in range(6) ] for j in range(6)]
def __init__(self) :
for d1 in range(6):
for d2 in range(6):
self._Val[d1][d2] = random.randint(0, 9)
def printVal(self) :
print(self._Val)
b1.printVal()
b2.printVal()
链接地址: http://www.djcxy.com/p/78784.html
上一篇: 单一方法的类