(Python Primary) - 廖雪峯Python3 - 9.面向對象高級編程

9.面向對象高級編程 9.1使用__slots__ 在動態語言中,實例能夠輕鬆綁定一個屬性,但直接綁定一個方法,對另外一個實例是不起做用的 >>> def set_age(self, age): # 定義一個函數做爲實例方法 ... self.age = age ... >>> from types import MethodType >>> s.set_age = MethodType(
相關文章
相關標籤/搜索