删除对象属性
删除对象属性详细操作教程
以下实例为学习删除对象属性,具体代码如下:
# Filename : example.py
# Author by : www.lidihuo.com
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def myfunc(self):
print("Hello my name is " + self.name)
p1 = Person("Bill", 63)
del p1.age
print(p1.age)
执行以上代码输出结果为:
# Filename : example.py
# Author by : www.lidihuo.com
Traceback (most recent call last):
File "demo_class7.py", line 13, in <module>
print(p1.age)
AttributeError: 'Person' object has no attribute 'age'