python 的类类型

soulmachine 2009-03-04 05:14:44

class Foo:pass

class Bar(object):pass

bar=Bar()
foo=Foo()

print type(Foo)
print type(foo)
print type(Bar)
print type(bar)

结果是
<type 'classobj'>
<type 'instance'>
<type 'type'>
<class '__main__.Bar'>

我想问的是,为什么Foo 和 Bar , foo 和 bar 有区别?
...全文
80 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
guzl86 2009-03-25
  • 打赏
  • 举报
回复
学习
huwen171 2009-03-21
  • 打赏
  • 举报
回复
学习
iambic 2009-03-04
  • 打赏
  • 举报
回复
Bar继承了object,而object是一个built-in的类型。
>>> print type(object)
<type 'type'>
>>> print type(int)
<type 'type'>

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧