python class Object

 一:爲何要使用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()

ps:python纔剛剛起步,加油!
相關文章
相關標籤/搜索