一:为何要使用python的类对象编程?python
个人理解:编程
1:便于维护、扩展代码。ide
2:更易于重复使用代码。对象
二:python 类对象编程代码以下:it
#建立firstClass类class
class firstClass:test
i=10变量
#定义hello方法,注意:python 的类方法必须传一个self参数扩展
def hello(self):方法
#必须经过self来访问类变量
for m in range(0,self.i):
print m
#建立类实例test
test=firstClass()
#经过实例调用方法
test.hello()