read.cash Log in
h@hbkedge more from that month

龍家俊教你 python day 31 修改類屬性 類屬性只能通過類對象修改,不能通過實例對象修改,如果通過實例對象修改類屬性,表示的是創建了一個實例屬性。 ``` python class Dog(object): tooth = 100 S = Dog() P = Dog() # 修改類屬性 Dog.tooth = 120 print(Dog.tooth) # 120 print(S.tooth) # 120 print(P.tooth) # 120 # 不能通過對象修改屬性,如果這樣操作,實則是創建了一個實例屬性 S.tooth = 200 print(Dog.tooth) # 120 print(S.tooth) # 200 print(P.tooth) # 120 #PttDigiCurrency

3 comments

Log in to join in Reading is open to everyone. Replying needs an account.