Python 3 教程
delattr 函數(shù)用于刪除屬性。
delattr(x, 'foobar') 相等于 del x.foobar。
delattr 語法:
delattr(object, name)
無。
以下實例展示了 delattr 的使用方法:
輸出結(jié)果:
('x = ', 10) ('y = ', -5) ('z = ', 0) --刪除 z 屬性后-- ('x = ', 10) ('y = ', -5) Traceback (most recent call last): File "test.py", line 22, in <module> print('z = ',point1.z) AttributeError: Coordinate instance has no attribute 'z'其他擴展