天天看點

8.1 類的一般形式

class ren(object):
    '''this class is about ren class。類的說明,使用三個單引号'''
    name='菇涼'
    sex='Female'
    def hello(self):
        print('hello world')
a=ren()
print(type(a))
print(a.name)
print(a.sex)
a.hello()
a.name='未來啊'
print(a.name)      

傳回結果:

<class '__main__.ren'>

菇涼

Female

hello world

未來啊

上一篇: 8.4 類的重寫
下一篇: 7.3 高階函數

繼續閱讀