클래스에서 이런 현상을 어떻게 설명하지요?
class Human():
print("hi")
만 있는데 그대로 실행하면
hi
가 나옵니다.. 왜그런걸까요??
numinojs 님 382
M 2021년 10월 21일 4:19 오후
1개의 답변이 있습니다. 1 / 1 Page
파이썬 클래스 문서를 보면 다음과 같이 나와 있습니다.
A class definition is an executable statement.
https://docs.python.org/3/reference/compound_stmts.html#class-definitions
class A:
<statements>
즉, 클래스는 인스턴스가 만들어지지 않더라도 위 처럼 클래스에 정의된 문장(statements)이 실행되네요.
박응용 님
2021년 10월 21일 4:34 오후