Python/Python with Error
[해결 방법] TypeError: object of type 'int' has no len()
HJ0216
2023. 8. 8. 12:19
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