python中最后一个基础知识点,面向对象
'''Created on 2011-9-30@author: xgzhao'''class MyData():pass#The instance attributes need not bo be defined in the class, just use itmathObj = MyData();mathObj.x = 3mathObj.y = 4print mathObj.x + mathObj.yprint mathObj.x * mathObj.yclass MyDataWithMethod():'the doc of this class'myData = 123def printFoo(self):print 'You invoked printFoo()'mathMethod = MyDataWithMethod()mathMethod.printFoo()print MyDataWithMethod.__doc__print MyDataWithMethod.__name__print MyDataWithMethod.__dict__
页:
[1]