object() 函數返回一個無特征對象,它是所有類的基礎。
用法:
o = object()
參數:
object()
函數不接受任何參數。
返回:
object()
函數返回一個無特征的對象。
示例:object() 如何工作?
test = object()
print(type(test))
print(dir(test))
輸出
<class '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__']
在這裏,創建了一個對象test
。
在程序中,我們使用type()來獲取對象的類型。
同樣,我們使用dir() 來獲取所有屬性。這些屬性(屬性和方法)對所有 Python 類的實例都是通用的。
相關用法
- Python object()用法及代碼示例
- Python os.path.normcase()用法及代碼示例
- Python os.read()用法及代碼示例
- Python os.DirEntry.inode()用法及代碼示例
- Python os.closerange()用法及代碼示例
- Python os.set_blocking()用法及代碼示例
- Python os.pathconf()用法及代碼示例
- Python os.chflags()用法及代碼示例
- Python operator.truth()用法及代碼示例
- Python operator.le()用法及代碼示例
- Python os.WCOREDUMP()用法及代碼示例
- Python os.fork()用法及代碼示例
- Python os.ctermid()用法及代碼示例
- Python os.mkfifo()用法及代碼示例
- Python os.tcsetpgrp()用法及代碼示例
- Python os.path.commonpath()用法及代碼示例
- Python os.mkdir()用法及代碼示例
- Python os.close()用法及代碼示例
- Python os.chroot()用法及代碼示例
- Python os.path.expanduser()用法及代碼示例
注:本文由純淨天空篩選整理自 Python object()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。