반응형
함수나 모듈이 정의되기 전에 호출
문제 코드:
greet()
def greet():
print("Hello, World!")
오류 메시지:
NameError: name 'greet' is not defined
해결 방법: 함수나 모듈을 호출하기 전에 먼저 정의해야 합니다.
def greet():
print("Hello, World!")
greet()
python에서 NameError를 피하기 위해 변수, 함수 또는 모듈을 사용하기 전에 반드시 정의하고, 정확한 이름을 사용해야 합니다
반응형
'파이썬 > 에러 디버깅' 카테고리의 다른 글
TypeError: can't multiply sequence by non-int of type 'list' (0) | 2024.08.17 |
---|---|
TypeError: can only concatenate str (not "int") to str (0) | 2024.08.17 |
NameError: name 'nam' is not defined (0) | 2024.08.10 |
NameError: name 'name' is not defined (0) | 2024.08.10 |
IndentationError: unindent does not match any outer indentation level (0) | 2024.08.04 |