Language/Python
[Python] Vars( ) 함수
밴나루
2022. 5. 10. 19:13
반응형
Vars([object])란?
python의 기본 내장함수로서 모듈, 클래스, 클래스 인스턴스 객체(__dict__속성을 가지는 객체)에 대해 __dict__ (dictionary 형태)로 return해 주는 함수임.
만약 [object]를 선언하지 않으면 locals()처럼 동작되어 현재 지역 변수에 대해 __dict__(dictionary 형태)로 return함.
Vars 함수 예제
class SellList:
snack = 1000
ice_cream = 700
coke = 1200
candy = 1500
print(vars(SellList))
# 출력 화면
{'__module__': '__main__', 'snack': 1000, 'ice_cream': 700, 'coke': 1200, 'candy': 1500, '__dict__': <attribute '__dict__' of 'SellList' objects>, '__weakref__': <attribute '__weakref__' of 'SellList' objects>, '__doc__': None}
728x90