In[1]: dir(obj)

Out[1]:['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
?
和我们对任何常规的对象调用dir函数一样,得到的是一堆带双前后导下划线的特殊属性,现在来做点有意义的事情:对他们进行分类

1.rich comparison operator:
  __lt__, __gt__, __le__, __ge__, __eq__, __ne__
2.attribute management
  __getattribute__, __delattr__, __setattr__, __dir__
  特别要注意的是,这里没有__getattr__,因为它只有在试图访问一个不存在的属性时,由__getattribute__方法报AttributeError错误后才会调用
3.string representation
  __repr__, __str__, __format__
4.instance creation and destruction
  __new__, __init__, __init_subclass__
5.memory management
  __sizeof__(一般会调用sys.getsizeof())
6.comversion to number
  __hash__
7.pickling
  __reduce__, __reduce_ex__
  与对象的序列化相关的特殊方法。这里的reduce是用于控制自定义类的扩展类行为,不是fuctools中的reduc()函数所触发的方法。
8.virtual subclass implicit registering
  __subclasshook__
  实现这个特殊方法后,解释器会自动检测某个自定义的类是否定义了一些指定的特殊方法,检测的实质是在自定义的类(及其各级父类)的属性__dict__中寻找是否出现特殊方法。

上述1-8皆为特殊方法,下面的9显示了这个最普通的object类的实例obj的特殊属性及其值:
9.
  1)__class__:object
  2)__doc__:'The most base type'

最新文章

  1. 【腾讯Bugly干货分享】WebVR如此近-three.js的WebVR示例解析
  2. Man——send(2)翻译
  3. JS获取当前时间并把时间赋给input表单
  4. visual studio 引用lib
  5. Jade之注释
  6. Listview之优化BaseAdapter中的getView中的contentView
  7. css 利用border属性制作箭头 Using Borders to Make Pure CSS Arrows
  8. 我的django之旅(一)
  9. SDK Manager 报错:Connection timed out: connect
  10. js面向对象oop编程
  11. 仿中关村win8频道(win8.zol.com.cn)下的tab效果
  12. 模仿ICE的structured panorama小按钮
  13. 【codevs1001】[bzoj1050]舒适的路线
  14. TurnipBit口袋编程计算机:和孩子一起DIY许愿的流星
  15. pandas教程
  16. 基于SpringBoot+Mybatis+AntDesign快速开发平台,Jeecg-Boot 1.1 版本发布
  17. html跳动的心实现代码
  18. 100.Same Tree(E)
  19. VUE CLI 3.0 项目引入 ElementUI
  20. Codeforces-gym-101020 problem C. Rectangles

热门文章

  1. centos6 编译安装gcc4.8.2
  2. Rich feature hierarchies for accurate object detection and semantic segmentation(RCNN)
  3. 分类算法简介 基于R
  4. kmeans聚类中的坑 基于R shiny 可交互的展示
  5. Thinkphp 5 使用DOMDocument
  6. 使用jdk进行数据迁移(sqlite迁移mysql)
  7. Git基础篇
  8. django视图层(views)
  9. WebStrome react-native代码智能提示
  10. Map the Debris -freecodecamp算法题目