內置函數對象()返回一個空對象。這個對象是所有類的基礎。它保存默認的內置屬性和方法。不可能向該對象添加新的屬性或方法。
**o = object()** #where o is the object
對象()參數:
object()
函數不接受任何參數。
對象()返回值
object()
函數返回一個無特征的對象。這是所有階層的基礎。
Python 中object()
方法的示例
示例object()
是如何工作的?
test = object()
print(type(test))
print(dir(test))
輸出:
test = object()
print(type(test))
print(dir(test))
示例 2:演示對象的屬性()
# declaring the objects of class object
obj1 = object()
obj2 = object()
# checking for object equality
print ("Is obj1 equal to obj2 : " + str(obj1 == obj2))
# trying to add attribute to object
obj1.name = "GeeksforGeeks"
輸出:
Is obj1 equal to obj2 : False