英文文檔:shell
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.less
說明:ssh
1. object類是Python中全部類的基類,若是定義一個類時沒有指定繼承哪一個類,則默認繼承object類。spa
>>> class A: pass >>> issubclass(A,object) True
2. object類定義了全部類的一些公共方法。code
>>> dir(object) ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
3. object類沒有定義 __dict__,因此不能對object類實例對象嘗試設置屬性值。orm
>>> 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' # 能設置屬性