0
Pls can someone make me understand this
>>> "2" + "2" '22' >>> 1 + '2' + 3 + '4' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'int' and 'str'
5 Antworten
+ 2
Hi, becouse you try concatenite two different type values: number (int) and strings (str)
+ 2
//Answer is there in your error log
Pls can someone make me understand this
TypeError: unsupported operand type(s) for +: 'int' and 'str'
+ 2
You are literally adding two impossible things. A string and an integer.
Like saying you're adding
a + 1
Technically the computer does not know how to add so it throws an error. The best way to solve is to change all to a common data type. Either all as integers or either all as a string.
int() for changing it to integers
str() for changing to strings.
+ 1
You can fix the error by either using str() or int():
str(1) + '2' + str(3) + '4'
>>>'1234'
1 + int('2') + 3 + int('4')
>>>10
0
Thanks