delattr(object, name)
中文说明:删除object对象名为name的属性。这个函数的命名真是简单易懂啊,和jquery里面差不多,但是功能不一样哦,注意一下。
参数object:对象。
参数name:属性名称字符串。
版本:各版本中都支持该函数,python3中仍可用。
立即学习“Python免费学习笔记(深入)”;
英文说明: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']
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号