pythonExample100/JCP041.py

28 lines
485 B
Python
Raw Permalink 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.

'''
【程序41】
题目学习static定义静态变量的用法   
1.程序分析:
2.程序源代码:
'''
# python没有这个功能了,只能这样了:)
def varfunc():
var = 0
print 'var = %d' % var
var += 1
if __name__ == '__main__':
for i in range(3):
varfunc()
# attribut of class
# 作为类的一个属性吧
class Static:
StaticVar = 5
def varfunc(self):
self.StaticVar += 1
print self.StaticVar
print Static.StaticVar
a = Static()
for i in range(3):
a.varfunc()