''' Created on 2011-9-30 @author: xgzhao ''' class MyData(): pass #The instance attributes need not bo be defined in the class, just use it mathObj = MyData(); mathObj.x = 3 mathObj.y = 4 print mathObj.x + mathObj.y print mathObj.x * mathObj.y class MyDataWithMethod(): 'the doc of this class' myData = 123 def printFoo(self): print 'You invoked printFoo()' mathMethod = MyDataWithMethod() mathMethod.printFoo() print MyDataWithMethod.__doc__ print MyDataWithMethod.__name__ print MyDataWithMethod.__dict__
python中最后一个基础知识点,面向对象
最新推荐文章于 2024-08-14 12:00:04 发布