delatr()는 개체에서 속성을 삭제합니다(개체가 허용하는 경우).
delattr()은 값을 반환하지 않습니다(None을 반환).
개체에서 허용하는 경우에만 속성을 제거합니다.
class Coordinate:
x = 10
y = -5
z = 0
point1 = Coordinate()
print('x = ',point1.x)
print('y = ',point1.y)
print('z = ',point1.z)
delattr(Coordinate, 'z')
print('--z 속성을 삭제한 다음--')
print('x = ',point1.x)
print('y = ',point1.y)
# Raises Error
print('z = ',point1.z)
결과
x = 10
y = -5
z = 0
--z 속성을 삭제한 다음
--
x = 10
y = -5
Traceback (most recent call last):
File "python", line 19, in <module>
AttributeError: 'Coordinate' object has no attribute 'z'
© 2022 pinfo. All rights reserved.