掃二維碼與項(xiàng)目經(jīng)理溝通
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
delattr()函數(shù)將一個(gè)對(duì)象作為參數(shù),并從該對(duì)象中移除一個(gè)屬性。

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),增城企業(yè)網(wǎng)站建設(shè),增城品牌網(wǎng)站建設(shè),網(wǎng)站定制,增城網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,增城網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
**delattr(object, name)** #where name is the name of attribute
delattr()參數(shù):該函數(shù)將一個(gè)對(duì)象作為參數(shù),要?jiǎng)h除的屬性可以作為可選參數(shù)傳遞。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 一個(gè)對(duì)象 | 要從中刪除屬性的對(duì)象 | 需要 |
| 屬性 | 要移除的屬性的名稱 | 可選擇的 |
delattr()函數(shù)不返回任何內(nèi)容。它只從對(duì)象中移除屬性
delattr()方法的示例 class Student:
name = "Ram" age = 22
course = "Bachelors"
Student1 = Student()
delattr(Student, 'age') #Removing age attribute
print("Student's name is ",Student 1.name)
print("Student's country is ",Student 1.country)
print("Student's age is ",Student 1.age) # Raises error since age is not found
輸出:
Student's name is John
Student's country is Norway
AttributeError: 'Student' object has no attribute 'age'
delattr()是如何工作的? class Coordinate:
x = 20
y = -15
z = 0
value1 = Coordinate()
print('x = ',value1.x)
print('y = ',value1.y)
print('z = ',value1.z)
delattr(Coordinate, 'z')
print('--After deleting z attribute--')
print('x = ',value1.x)
print('y = ',value1.y)
# Raises Error
print('z = ',value1.z)
輸出:
x = 20
y = -15
z = 0
--After deleting z attribute--
x = 20
y = -15
Traceback (most recent call last):
File "python", line 19, in AttributeError: 'Coordinate' object has no attribute 'z' 
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流