【Python深入】Python中继承object和不继承object的区别
16lz
2021-01-22
python中定义class的时候,有object和没有object的不同?例如:
class Solution(object):
class Solution():
这俩的区别在于——————
在python2.x中,通过分别继承自object和不继承object定义不同的类,之后通过dir()和type分别查看该类的所有方法和类型:
>>> class test(object): ... pass ... >>> dir(test) ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '_ _init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__size of__', '__str__', '__subclasshook__', '__weakref__'] >>> type(test) <type 'type'> >>> class test2(): ... pass ... >>> dir(test2) ['__doc__', '__module__'] >>> type(test2) <type 'classobj'>
更多相关文章
- classmethod,staticmethod,还有类里面一般的的method有什么区别
- Python第十天 print >> f,和fd.write()的区别 stdout的buffer 标
- Python NameError:全局名称“Form”没有定义pyqt
- django-modeltranslation:如何知道该值是否在给定语言中定义?
- python中None与Null的区别
- RobotFramework中加载自定义python包中的library(一个py文件中有
- Django rest framework 使用自定义认证方式
- python学习笔记:python 2与python 3的一些小区别
- Python:Sympy定义与包含变量的边界的积分