鱼C论坛

 找回密码
 立即注册
查看: 4807|回复: 7

type和dir的区别是啥啊

[复制链接]
发表于 2014-7-6 21:55:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
type和dir的区别是啥啊 。我看都能显示类型的
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-7-6 22:05:01 | 显示全部楼层
貌似不同吧~{:7_181:}
  1. >>> help(dir)
  2. Help on built-in function dir in module builtins:

  3. dir(...)
  4.     dir([object]) -> list of strings
  5.    
  6.     If called without an argument, return the names in the current scope.
  7.     Else, return an alphabetized list of names comprising (some of) the attributes
  8.     of the given object, and of attributes reachable from it.
  9.     If the object supplies a method named __dir__, it will be used; otherwise
  10.     the default dir() logic is used and returns:
  11.       for a module object: the module's attributes.
  12.       for a class object:  its attributes, and recursively the attributes
  13.         of its bases.
  14.       for any other object: its attributes, its class's attributes, and
  15.         recursively the attributes of its class's base classes.

  16. >>> dir(dir)
  17. ['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__text_signature__']
  18. >>> help(help)
  19. Help on _Helper in module _sitebuiltins object:

  20. class _Helper(builtins.object)
  21. |  Define the builtin 'help'.
  22. |  This is a wrapper around pydoc.help (with a twist).
  23. |  
  24. |  Methods defined here:
  25. |  
  26. |  __call__(self, *args, **kwds)
  27. |  
  28. |  __repr__(self)
  29. |  
  30. |  ----------------------------------------------------------------------
  31. |  Data descriptors defined here:
  32. |  
  33. |  __dict__
  34. |      dictionary for instance variables (if defined)
  35. |  
  36. |  __weakref__
  37. |      list of weak references to the object (if defined)

  38. >>> dir(help)
  39. ['__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
  40. >>>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-7-7 17:58:46 From FishC Mobile | 显示全部楼层
你暂时可以认为“type是显示对象的类型”而“dir是显示对象有什么属性和方法”。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2014-7-10 11:36:06 | 显示全部楼层
小甲鱼 发表于 2014-7-7 17:58
你暂时可以认为“type是显示对象的类型”而“dir是显示对象有什么属性和方法”。

也就是说dir比较强大咯?

点评

显示的是不同的东西丫。  详情 回复 发表于 2014-7-10 14:59
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-7-10 14:59:01 | 显示全部楼层
admin. 发表于 2014-7-10 11:36
也就是说dir比较强大咯?

显示的是不同的东西丫。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-7-11 07:01:56 | 显示全部楼层
小甲鱼 发表于 2014-7-10 14:59
显示的是不同的东西丫。

这么说是这样:
type(123)
然后回复的是int
dir(type)
显示的是内置什么来着?的用法

点评

>>> dir(type) ['__abstractmethods__', '__base__', '__bases__', '__basicsize__', '__call__', '__class__', '__delattr__', '__dict__', '__dictoffset__', '__dir__', '__doc__', '__eq__', '__flags__', '__f  详情 回复 发表于 2014-7-11 14:10
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-7-11 14:10:41 | 显示全部楼层
admin. 发表于 2014-7-11 07:01
这么说是这样:
type(123)
然后回复的是int

>>> dir(type)
['__abstractmethods__', '__base__', '__bases__', '__basicsize__', '__call__', '__class__', '__delattr__', '__dict__', '__dictoffset__', '__dir__', '__doc__', '__eq__', '__flags__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__instancecheck__', '__itemsize__', '__le__', '__lt__', '__module__', '__mro__', '__name__', '__ne__', '__new__', '__prepare__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasscheck__', '__subclasses__', '__subclasshook__', '__text_signature__', '__weakrefoffset__', 'mro']

显示的是type对象的属性和方法,学习到“类和对象”一章节你就清楚了。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-7-11 15:08:50 | 显示全部楼层
dir是目录表吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-14 13:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表