Re: [問題] 請教一個很蠢的問題@@
有個 module 叫 types,內建的 type/class 都放在這個 module 裡,包括
old-style class 的共通型別(types.ClassType),old-style object 的共通
型別 types.InstanceType。
當你想要某種 builtin 型別的 type object reference,你沒有辦法直接寫出
type literal(比如你例中的 function type),記得來這個 module 找。
def statement 執行後產生的 function object 是 types.FunctionType 的
instance。
def foo(): pass
isinstance(foo, types.FunctionType) // True
type(foo) is types.FunctionType // True
foo.__class__ is types.FunctionType // True
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.173.253.133
※ 編輯: sbrhsieh 來自: 1.173.253.133 (07/09 20:27)
→
07/09 20:30, , 1F
07/09 20:30, 1F
推
07/09 23:07, , 2F
07/09 23:07, 2F
推
07/10 03:41, , 3F
07/10 03:41, 3F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
問題
2
7