python class with or without "inheritance from object "

  • Reference
    python class and inheritance of object

  • To make the concept as concise as possible, I won't discuss things too much around the historical fact, instead, let me just state the real use of python class in inheritance of object

  • To understand we must first know there are python2 and python3 versions and the class style contains new style and classic style.

    • Difference between new style and classic style
      • There is something around Depth-First Search and Breadth-First Search, and the new tends to be inclined of Breadth-First where old tends to be inclined of Depth-First. For more details of the difference between this 2, visite this link.
      • Python2 uses either old or new where Python3 uses only new as its default form.
    • HOW-TO implements old new for p2, p3 respectively.
      • In python2
      # Python2.x中,默认都是经典类,只有显式继承了object才是新式类,即:
      class Person(object):pass               # 新式类写法
      class Person():pass                     # 经典类写法
      class Person:pass                       # 经典类写法
      
      • in python3
      # 在Python 3.x中取消了经典类,默认都是新式类,
      # 并且不必显式的继承object,也就是说:
      class Person(object):pass
      class Person():pass
      class Person:pass
      # 三种写法并无区别,推荐第一种
      
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。