函数学习-delattr()
生活随笔
收集整理的這篇文章主要介紹了
函数学习-delattr()
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 attribute, provided the object allows it. For 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']轉載于:https://blog.51cto.com/yayang/1608517
總結
以上是生活随笔為你收集整理的函数学习-delattr()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【二分答案】【哈希表】【字符串哈希】bz
- 下一篇: C#函数式编程之标准高阶函数