作者sbrhsieh (偶尔想摆烂一下)
看板Python
标题Re: [问题] 数值型态
时间Sat Nov 27 18:46:34 2010
※ 引述《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)