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 "
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...