標籤: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的物件導向-類的資料屬性和執行個體的資料屬性相結合-無命名看你懵逼不懵逼系列