Python內建函數Object

來源:互聯網
上載者:User

標籤:ace   highlight   hat   assign   obj   common   set   nts   __str__   

英文文檔

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類

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

  

object類定義了所有類的一些公用方法

>>> 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__‘]

  

object沒有定義__dict__,所以不能對object類執行個體對象嘗試設定屬性

>>> 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‘ # 能設定屬性

  

zhuanzai

 

Python內建函數Object

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.