상추의 IT저장소
Py)TypeError: can only concatenate str (not "int") to str 해결방법 본문
파이썬 공부중에 태어난 년도를 입력받으면 현재나이를 출력하는 예제를 풀던 중 해당 오류가 확인되었다.
currentYear = int(2023)
birthYear = int(input("출생연도를 입력해주세요"))
age = int(currentYear-birthYear)
print("현재나이는"+ age +"입니다")

- 파이썬의 경우에는 숫자와 문자를 합쳐서 출력할 경우 에러가 발생한다고 한다.
- age를 str자료형으로 형변환 시켜서 출력하니 정상적으로 출력되었다.
print("현재나이는"+ str(age) +"입니다")

'error' 카테고리의 다른 글
| Git) warning: adding embedded git repository 해결 (0) | 2023.01.12 |
|---|---|
| err) TypeScript 오류 - 이 시스템에서 스크립트를 실행할 수 없으므로... (0) | 2023.01.11 |
| Git) There isn’t anything to compare 해결 방법 (0) | 2023.01.10 |
| React) export 'Routes' (imported as 'Routes') was not found in 'react-router-dom' (0) | 2022.12.18 |
| error) VSCode 파일 자동 저장 설정/해제 (0) | 2022.11.26 |