Skip to content

Latest commit

 

History

History
35 lines (29 loc) · 624 Bytes

36.md

File metadata and controls

35 lines (29 loc) · 624 Bytes
@author jackzhenguo
@desc 
@date 2019/3/10

36 动态删除属性  

>>> class Student():
    def __init__(self,id,name):
        self.id = id
        self.name = name
    def __repr__(self):
        return 'id = '+self.id +', name = '+self.name

调用:

>>> xiaoming = Student(id='1',name='xiaoming')
>>> xiaoming
id = 1, name = xiaoming
>>> ascii(xiaoming)
'id = 1, name = xiaoming'

删除对象的属性

In [1]: delattr(xiaoming,'id')

In [2]: hasattr(xiaoming,'id')
Out[2]: False
[上一个例子](35.md) [下一个例子](37.md)