python的物件導向-類的資料屬性和執行個體的資料屬性相結合-無命名看你懵逼不懵逼系列

來源:互聯網
上載者:User

標籤:sel   +++   input   self   類的屬性   訪問   對象   接受   count   

1、

class Chinese:    country=‘China‘    def __init__(self,name):        self.name=name    def play_ball(self,ball):        print(‘%s 正在打 %s‘ %(self.name,ball))p1=Chinese("北爺")print(p1.country)#這是訪問的類的資料屬性p1.country="日本人"#增加了一個執行個體的資料屬性print(Chinese.country)#調用類的資料屬性print(p1.country)#調用執行個體的資料屬性,因為上面增加了執行個體的country屬性是日本人C:\python35\python3.exe D:/pyproject/day24/類屬性與執行個體屬性結合.pyChinaChina日本人

2、

class Chinese:    country = ‘中國‘    def __init__(self,name):        print("執行個體化先運行init------->")        self.name=name    def play_ball(self,ball):        print(‘%s 正在打 %s‘ %(self.name,ball))def shi_li_hua():#定義一個執行個體化函數    name=input(">>>")#接受一個值賦值給name    p1=Chinese(name)#執行個體化一個p1執行個體    print(p1.country)#調用執行個體的類的資料屬性shi_li_hua()#運行shilihua這個函數,前面都是定義,把那些載入到記憶體,這才是程式啟動並執行第一步,然後風濕理論向上找,範圍

3、

country="中國"class Chinese:    country = ‘中國+++‘    def __init__(self,name):        self.name=name        print("---->",country)#這個country不是用.調用的,既不是類的屬性也不是執行個體的屬性,就是一個普通的變數,遵循風濕理論    def play_ball(self,ball):        print(‘%s 正在打 %s‘ %(self.name,ball))p1=Chinese("北爺")#執行個體化一個p1執行個體C:\python35\python3.exe D:/pyproject/day24/類屬性與執行個體屬性結合.py----> 中國

4、

country="中國++"class Chinese:    country = ‘中國‘    def __init__(self,name):        self.name=name        print("普通變數",country)#這個country不是用.調用的,既不是類的屬性也不是執行個體的屬性,就是一個普通的變數    def play_ball(self,ball):        print(‘%s 正在打 %s‘ %(self.name,ball))print(country)#調用全域範圍的countryprint(Chinese.country)#調用類的資料屬性countryp1=Chinese("北爺")#執行個體化一個p1執行個體print(p1.country)#調用執行個體的類的資料屬性,執行個體字典裡面沒有,就去類字典裡去找C:\python35\python3.exe D:/pyproject/day24/類屬性與執行個體屬性結合.py中國++中國普通變數 中國++中國

5、

class Chinese:    country=‘China‘    l=["a","b"]#存在類的屬性字典裡面    def __init__(self,name):        self.name=name    def play_ball(self,ball):        print(‘%s 正在打 %s‘ %(self.name,ball))p1=Chinese("北爺")print(p1.l)#執行個體p1調用類的資料屬性lp1.l=[1,2,3]#給執行個體p1增加一個資料屬性l,存在p1的屬性字典裡面print(Chinese.l)#調用類的資料屬性print(p1.l)#調用執行個體的資料屬性C:\python35\python3.exe D:/pyproject/day24/換個姿勢搞你.py[‘a‘, ‘b‘][‘a‘, ‘b‘][1, 2, 3]

6、

class Chinese:    country=‘China‘    l=["a","b"]#存在類的屬性字典裡面    def __init__(self,name):        self.name=name    def play_ball(self,ball):        print(‘%s 正在打 %s‘ %(self.name,ball))p1=Chinese("北爺")print(p1.l)#執行個體p1調用類的資料屬性lp1.l.append("c")#給執行個體調用的類的資料屬性增加一個cprint(Chinese.l)C:\python35\python3.exe D:/pyproject/day24/換個姿勢搞你.py[‘a‘, ‘b‘][‘a‘, ‘b‘, ‘c‘]

python的物件導向-類的資料屬性和執行個體的資料屬性相結合-無命名看你懵逼不懵逼系列

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.