新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythondelattr()
delattr()函數(shù)將一個對象作為參數(shù),并從該對象中移除一個屬性。

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),增城企業(yè)網(wǎng)站建設(shè),增城品牌網(wǎng)站建設(shè),網(wǎng)站定制,增城網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,增城網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
**delattr(object, name)** #where name is the name of attribute
delattr()參數(shù):
該函數(shù)將一個對象作為參數(shù),要刪除的屬性可以作為可選參數(shù)傳遞。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 一個對象 | 要從中刪除屬性的對象 | 需要 |
| 屬性 | 要移除的屬性的名稱 | 可選擇的 |
延遲()返回值
delattr()函數(shù)不返回任何內(nèi)容。它只從對象中移除屬性
Python 中delattr()方法的示例
示例 1:從對象中移除屬性
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' 分享標(biāo)題:創(chuàng)新互聯(lián)Python教程:Pythondelattr()
文章鏈接:http://www.dlmjj.cn/article/djgjjhg.html


咨詢
建站咨詢
