python - delattr(對象,名稱)

高洛峰
發布: 2016-10-17 14:52:44
原創
1289 人瀏覽過

delattr(object, name)

中文說明:刪除object物件名稱為name的屬性。這個函數的命名真是簡單易懂啊,跟jquery裡面差不多,但是功能不一樣哦,注意一下。

參數object:物件。

參數name:屬性名稱字串。

版本:各版本中都支援該函數,python3中仍可用。

英文說明:This is a relative of setattr(). The arguments are an object and a string. The string must be the name of one of the object's attributes. The function deletes the named attrib, provided the example, delattr(x, 'foobar') is equivalent to del x.foobar.

程式碼實例:

>>> class Person:
...     def __init__(self, name, age):
...             self.name = name
...             self.age = age
...
>>> tom = Person("Tom", 35)
>>> dir(tom)
['__doc__', '__init__', '__module__', 'age', 'name']
>>> delattr(tom, "age")
>>> dir(tom)
['__doc__', '__init__', '__module__', 'name']
登入後複製


   


   

🎜🎜🎜🎜 
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!