Re: [問題] 數值型態

看板Python作者 (偶爾想擺爛一下)時間14年前 (2010/11/27 18:46), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
※ 引述《shihyuyao (Yao)》之銘言: : http://caterpillar.onlyfun.net/Gossip/Python/NumericType.html : 無論是十進位、八進位或十六進位整數,都是int類別的實例: : <class 'int'> : <class 'int'> : <class 'int'> : 上面教學是說任何數值型態都是物件但我在python 2.7 測試 : <type 'int'> : 為什麼不是顯示 <class 'int'>?? : 謝謝 在舊時代的 Python 中,type 是 type,class 是 class,各種 type 可以看成是 build-in class,Python code 定義的(只能)是 class(type 必須在 C 層面 去實做)。 *預期獲得 type 的函式不接受 class。 到了 Python 2.2 開始引進 new-style class,這時候 Python code 定義的(new- style)class 與內建的 type 的差異縮小。我習慣把內建的 class 與 user-defined class 都視為相同的東西(視為 class)。一個例外是內建的 "type" class, type 是 class's class(metaclass),用來建構 class。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ※ 編輯: sbrhsieh 來自: 163.29.220.122 (11/27 18:47)
文章代碼(AID): #1CyE6EZp (Python)
文章代碼(AID): #1CyE6EZp (Python)