본문 바로가기
Error

[ERROR] TypeError: can only concatenate str (not "int") to str

by 챠챠12 2020. 8. 2.

TypeError: can only concatenate str (not "int") to str

 

문자와 숫자를 같이 출력하기 위해서 아래와 같이 작성해서 실행했습니다.

count = int(input())

for i in range(count):
    a,b = map(int, input().split())
    print("Case #" + (i+1) +": " + a + " + " + b + " = " + (a+b))

 

그러나,

이와 같은 TypeError가 났습니다.. 문자와 숫자를 같이 쓸 수 없기 때문에 나타난 오류였습니다!! 

즉, print 할 때는 같은 자료형만 가능합니다!!!

 

숫자 부분을 str(숫자) 와 같이 변경해 출력했습니다!!

count = int(input())

for i in range(count):
    a,b = map(int, input().split())
    print("Case #" +str(i+1)+": " + str(a) + " + " + str(b) + " = " + str(a+b))
LIST

댓글