반응형
저는 현재 파이썬을 배우고 있으므로 무슨 일이 일어나고 있는지 전혀 모릅니다.
num1 = int(input("What is your first number? "))
num2 = int(input("What is your second number? "))
num3 = int(input("What is your third number? "))
numlist = [num1, num2, num3]
print(numlist)
print("Now I will remove the 3rd number")
print(numlist.pop(2) + " has been removed")
print("The list now looks like " + str(numlist))
프로그램을 실행하여 num1, num2 및 num3에 숫자를 입력하면 다음과 같이 반환됩니다. 역 추적 (가장 최근 호출 마지막) :
TypeError: unsupported operand type(s) for +: 'int' and 'str'
해결 방법
잘못된 문자열과 정수를 연결하려고합니다.
print (numlist.pop (2) + "has been removed")
를 다음 중 하나로 변경합니다.
int
에서 str
로의 명시 적 변환 :
print(str(numlist.pop(2)) + " has been removed")
+
대신 ,
사용 :
print(numlist.pop(2), "has been removed")
문자열 형식 :
print("{} has been removed".format(numlist.pop(2)))
참조 페이지 https://stackoverflow.com/questions/20441035
반응형
'파이썬' 카테고리의 다른 글
파이썬 존재하지 않는 경우 새 파일에 쓰고있는 경우 파일에 추가 (0) | 2020.12.28 |
---|---|
파이썬 kivy에서 버튼 또는 레이블 텍스트 색상 변경 (0) | 2020.12.27 |
파이썬 pandas.Series에 항목을 추가 하시겠습니까? (0) | 2020.12.27 |
파이썬 Python PIL NameError 전역 이름 이미지가 정의되지 않았습니다. (0) | 2020.12.27 |
파이썬 How to use 2to3 properly for python? (0) | 2020.12.27 |
댓글