반응형

파이썬/에러 디버깅 15

IndentationError: unexpected indent

파이썬에서 들여쓰기는 항상 중요합니다 그래서 파이썬에서 들여쓰기의 레벨 수준이 맞지 않을 경우 IndentationError: unexpected indent 에러가 발생합니다. 들여쓰기 수준 불일치문제 코드:if True: print("First line") print("Second line") 오류 메시지:IndentationError: unexpected indent 해결 방법: 들여쓰기는 일정한 간격(보통 공백 4칸)으로 일관되게 유지해야 합니다. if True: print("First line") print("Second line")  위 처럼 if 문에서 True뒤의 print문은 같은 레벨의 수준이기 때문에 같은 들여쓰기 수준을 유지해줘야 합니다. #indentati..

IndentationError: expected an indented block

파이썬에서 들여쓰기를 하지 않는 경우 IndentationError: expected an indented block 와 같은 에러가 나타납니다  들여쓰기가 없는 경우문제 코드:def greet():print("Hello, World!") 오류 메시지:IndentationError: expected an indented block 해결 방법: 함수 블록 안의 코드는 들여쓰기를 사용해야 합니다.def greet(): print("Hello, World!")  위와 같이 들여쓰기를 잘못 했을 경우 해당 들여쓰기를 해주게 되면 해당 오류는 없어지게 됩니다 #python #error #debug #indentatioinError #파이썬 #에러

SyntaxError: invalid syntax

파이썬에서 잘못된 예약어를 사용시에 SyntaxError: invalid syntax 가 발생합니다.  잘못된 예약어 사용문제 코드:if True print("This is True")  오류 메시지:SyntaxError: invalid syntax 해결 방법: if 문이나 다른 조건문에서는 조건을 작성한 후에 콜론(:)을 추가해야 합니다. if True: print("This is True")   위와 같이 항상 조건문에서는 콜론이 있는지 확인을 하여야 하고 문법이 제대로 되었는지를 확인하여야 합니다.

SyntaxError: unexpected EOF while parsing

파이썬에서 괄호가 닫히지 않은 경우  SyntaxError: unexpected EOF while parsing 가 발생합니다. 괄호가 닫히지 않은 경우문제 코드:print("Hello, World!"  오류 메시지:SyntaxError: unexpected EOF while parsing  해결 방법: 모든 여는 괄호에는 닫는 괄호가 있어야 합니다. print("Hello, World!")   괄호를 열고 닫는 여부를 항상 확인 해 주셔야 합니다.   #python #error #debug #syntaxError

SyntaxError: expected an indented block

파이썬에서  SyntaxError: expected an indented block 와 같은 에러가 날 경우 들여쓰기가 잘못 되었을때 발생하기 마련 입니다. 문제 코드: 아래와 같이 def 다음에는 들여쓰기가 와야 합니다def example():print("Hello, World!") 오류 메시지:SyntaxError: expected an indented block 해결 방법: 함수나 조건문 등의 블록 안에서는 들여쓰기를 사용해야 합니다.def example(): print("Hello, World!")   위와 같이 들여쓰기를 완료 하여주면 해당 함수 실행시 문제 없이 코드가 진행되는 것을 보실수 있습니다.     #파이썬 #error #syntaxError #expected #debug

반응형