👉 기본 환경

- Language: Python

- IDE: Replit

 

 

⌨️ 코드

1
2
print(len(12345));
 
 

 

 

🖨️오류

TypeError: object of type 'int' has no len()

 

 

📡 원인

int는 len() 함수를 갖고 있지 않음

 

 

📰 해결 방법

1
2
print(len(str(12345)));
 
 

int를 str로 형변환 후 len() 사용

 

 

 

📚 참고 자료

 

[Python] int는 len()이 없대 ~~!

숫자의 길이를 구하려 len()함수를 사용했는데 다음과 같은 에러 발생!! 'int'는 len()함수를 갖고 있지 않기 때문이다...!🤭 해결방법간단 int에서 string으로 타입을 바꿔서 구한다! ex) 참고 discoverbits

euzl.github.io

 

👉 기본 환경

- Language: Python

- IDE: Replit

 

 

⌨️ 코드

1
2
1input = input("What is your name?")
 
 
 

 

 

🖨️오류

SyntaxError: invalid syntax

 

 

📡 원인

변수의 시작 글자는 숫자일 수 없음

 

 

📰 해결 방법

1
2
3
input1 = input("What is your name?")
_1input = input("What is your name?")
 
 
 

변수의 시작 글자를 문자 또는 _로 변경

 

👉 기본 환경

- Language: Python

- IDE: Replit

 

 

⌨️ 코드

1
2
input(Hello)
 
 

 

 

🖨️오류

NameError: name '...' is not defined

 

 

📡 원인

input()의 인자로 전달된 문자열은 사용자에게 입력을 요청하는 프롬프트로 표시

Hello에 "" 처리를 하지 않아 인자로 전달된 값이 문자열 처리가 되지 않고 변수로 인식됨

그러나, 변수로 선언한 적이 없어 not defined error 발생

 

 

📰 해결 방법

1
2
input("Hello")
 
 

문자열로 인식되도록 "" 추가

 

👉 기본 환경

- Language: Python

- IDE: Replit

 

 

⌨️ 코드

1
2
print(("New lines can be created with a backslash and n.")
 
 
 

 

 

🖨️오류

SyntaxError: unexpected EOF while parsing

 

 

📡 원인

괄호의 짝이 맞지 않음: ( - 2개, ) - 1개

 

 

📰 해결 방법

1
2
print("New lines can be created with a backslash and n.")
 
 
 

괄호의 짝이 맞도록 수정: ( - 1개, ) - 1개

 

👉 기본 환경

- Language: Python

- IDE: Replit

 

 

⌨️ 코드

1
2
 print("Hello World!\nHello World!\nHello World!")
 
 
 

 

 

🖨️오류

IndentationError: unexpected indent

 

 

📡 원인

print 실행 시, 맨 앞의 공백이 존재

 

 

📰 해결 방법

1
2
print("Hello World!\nHello World!\nHello World!")
 
 
 

맨 앞 공백 제거