看板 Python 關於我們 聯絡資訊
<class type> 跟 <class object> 搞不懂 在 python 裡面所有東西都是物件, 包含 class class Person: pass print( type(Person) ) # <class 'type'> print( isinstance(Person, type) ) # True ==> Person 是 <class type> 的一個 instance 於是我就想知道 <class type> 是什麼型別, 又做了下面測試 發現 <class type> 的型別是 <class type>, 然後又是自己的 instance?? print( type(type(Person)) ) # <class 'type'> print( isinstance(type(Person), type) ) # True 發現 <class object> 是 <class type> 的 instance print( type(object) ) # <class type> print( isinstance(object, type) ) # True 然後又發現 <class type> 也是 <class object> 的 instance? print( isinstance(type, object) ) 覺得非常困惑, 我以為所有物件的父類都是 <class object>, 搞不清楚 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.227.113.132 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1736505492.A.77D.html
cancelpc: class把它想成DNA(樣板) 01/10 19:25
cancelpc: object依DNA生產的人 01/10 19:26
cancelpc: object可以很多,但每個狀態不一樣 01/10 19:27
seLain: www.python.org/download/releases/2.2/descrintro/ 01/11 00:58
seLain: 需要釐清 isinstance 真實行為, metaclass, type system 01/11 00:59
seLain: 看看上面這篇是否能幫到你 01/11 01:00
lycantrope: metaclass 01/11 08:47
leolarrel: 我也學到了,感謝教學 01/13 11:42