Reference
python class and inheritance of objectTo 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
python class with or without "inheritance from object "
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。