728x90
👉 기본 환경
- 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
728x90
'Python > Python with Error' 카테고리의 다른 글
[해결 방법] TypeError: unsupported operand type(s) for /: 'str' and 'int' (0) | 2023.08.08 |
---|---|
[해결 방법] TypeError: can only concatenate str (not "int") to str (0) | 2023.08.08 |
[해결 방법] SyntaxError: invalid syntax (0) | 2023.08.06 |
[해결 방법] NameError: name '...' is not defined (0) | 2023.08.06 |
[해결 방법] SyntaxError: unexpected EOF while parsing (0) | 2023.08.05 |