1 class MemberCounter:
2 member = 0
3 def init(self):
4 self.member += 1
5 MemberCounter.member += 1
6
7 m1 = MemberCounter()
8 m1.init()
9 print(m1.member)
10 print(MemberCounter.member)
11
12 m2 = MemberCounter()
13 m2.init()
14 print(m2.member)
15 print(MemberCounter.member)
16
17 print(m1.member is m2.member)
18 print(m1.member is MemberCounter.member)
19 print(m2.member is MemberCounter.member)
20
21 m3 = MemberCounter()
22 m3.init()
23 print(m3.member)
24 print(MemberCounter.member)
25 print(m2.member is MemberCounter.member)
26
27 print(m1.member)
28 print(MemberCounter.member)
输出:
>>>
1
1
2
2
False
False
True
3
3
False
1
3
posted on 2013-05-18 16:43
unixfy 阅读(421)
评论(0) 编辑 收藏 引用