-
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
andpython3
versions and the class style containsnew style
andclassic 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 whereold
tends to be inclined of Depth-First. For more details of the difference between this 2, visite this link. -
Python2 uses either
old
ornew
where Python3 uses onlynew
as its default form.
- There is something around Depth-First Search and Breadth-First Search, and the
-
HOW-TO
implementsold
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 # 三种写法并无区别,推荐第一种
- Difference between new style and classic style
网友评论