pythonExample100/JCP043.py

21 lines
411 B
Python
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

'''
【程序43】
题目学习使用static的另一用法。   
1.程序分析:
2.程序源代码:
有一个static变量的用法python是没有演示一个python作用域使用方法
'''
class Num:
nNum = 1
def inc(self):
self.nNum += 1
print 'nNum = %d' % self.nNum
if __name__ == '__main__':
nNum = 2
inst = Num()
for i in range(3):
nNum += 1
print 'The num = %d' % nNum
inst.inc()