kaixin2018

原英文帮助文档:

class object

Return a new featureless object. object is a base for all classes. It has the methods that are common to all instances of Python classes. This function does not accept any arguments.

Note

object does not have a __dict__, so you can’t assign arbitrary attributes to an instance of the object class.

 

 

 

 

 

 

————————(我是分割线)————————

中文解释


返回一个新的无特征对象。object是所有类的基。它拥有所有python类实例通用的方法。此函数不接受任何参数。

object没有定义__dict__,所以不能对object类实例对象尝试设置属性 

 

Object类是Python中所有类的基类,如果定义一个类时没有指定继承那个类,则默认继承object类

>>> class A:
    pass
 
>>> issubclass(A,object)
True
issubclass(class, classinfo)

issubclass() 方法用于判断参数 class 是否是类型参数 classinfo 的子类

 

 

此函数runoob.com并未作介绍

object类定义了所有类的一些公共方法

>>> dir(object)
[\'__class__\', \'__delattr__\', \'__dir__\', \'__doc__\', \'__eq__\', \'__format__\', \'__ge__\', \'__getattribute__\', \'__gt__\', \'__hash__\', \'__init__\', \'__init_subclass__\', \'__le__\', \'__lt__\', \'__ne__\', \'__new__\', \'__reduce__\', \'__reduce_ex__\', \'__repr__\', \'__setattr__\', \'__sizeof__\', \'__str__\', \'__subclasshook__\']

 

示例:

>>> a = object()
>>> a.name = \'kim\' # 不能设置属性
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    a.name = \'kim\'
AttributeError: \'object\' object has no attribute \'name\'
 
#定义一个类A
>>> class A:
    pass
 
>>> a = A()
>>>
>>> a.name = \'kim\' # 能设置属性

 

 


————————(我是分割线)————————

参考:

1. Python 3.7.2 documentation

2. https://www.cnblogs.com/yyf573462811/p/9591678.html

 

 

备注:

初次编辑时间:2019年9月24日19:19:48

环境:Windows 7   / Python 3.7.2

 

分类:

技术点:

相关文章: