728x90 hasattr1 [python] hasattr(object, attribute) object에 attribute 속성이 있는지 참/거짓 여부 hasattr(object, attribute)는 object에 attribute 속성이 있으면 True, 없으면 False를 출력하는 함수를 이야기한다. class example: def __init__(self, x): self.x =x c = example(1) print(c.x) # 1 print(hasattr(c, 'x')) # True print(hasattr(c, 'y')) # False 주로 DL에서 속성이 있을 때 초기화 하는 용도로 사용한다. 2023. 11. 12. 이전 1 다음 728x90