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
      # 三种写法并无区别,推荐第一种
      

你可能感兴趣的:(python class with or without "inheritance from object ")