1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| class Test:
step: int = 0
def fun1(self):
self.step += 1
@classmethod
def fun2(cls):
cls.step += 2
if __name__ == "__main__":
# None : 인스턴스 변수가 없고 클래스 변수를 참조한다는 뜻
# [Test.step, test1.step, test2.step]
# [0, None, None]
test1 = Test() # -> [0, None, None]
test2 = Test() # -> [0, None, None]
Test.fun2() # -> [2, None, None]
test1.fun1() # -> [2, 3, None]
test1.fun2() # -> [4, 3, None]
test2.fun2() # -> [6, 3, None]
Test.fun2() # -> [8, 3, None]
test2.fun1() # -> [8, 3, 9]
test2.fun1() # -> [8, 3, 10]
test2.fun2() # -> [10, 3, 10]
test1.fun1() # -> [10, 4, 10]
|