[PYTHON] class類中內置方法


 內置方法  說明
 __init__(self,...)  初始化對象,在創建新對象時調用
 __del__(self)  釋放對象,在對象被刪除之前調用
 __new__(cls,*args,**kwd)  實例的生成操作
 __str__(self)  在使用print語句時被調用
 __getitem__(self,key)  獲取序列的索引key對應的值,等價於seq[key]
 __len__(self)  在調用內聯函數len()時被調用
 __cmp__(stc,dst)  比較兩個對象src和dst
 __getattr__(s,name)  獲取屬性的值
 __setattr__(s,name,value)  設置屬性的值
 __delattr__(s,name)  刪除name屬性
 __getattribute__()  __getattribute__()功能與__getattr__()類似
 __gt__(self,other)  判斷self對象是否大於other對象
 __lt__(slef,other)  判斷self對象是否小於other對象
 __ge__(slef,other)  判斷self對象是否大於或者等於other對象
 __le__(slef,other)  判斷self對象是否小於或者等於other對象
 __eq__(slef,other)  判斷self對象是否等於other對象
 __call__(self,*args)  把實例對象作為函數調用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM