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'

13th Feb 2020, 7:15 PM
Peter Emmanuel
Peter Emmanuel - avatar
5 Antworten
+ 2
Hi, becouse you try concatenite two different type values: number (int) and strings (str)
13th Feb 2020, 7:18 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
//Answer is there in your error log Pls can someone make me understand this TypeError: unsupported operand type(s) for +: 'int' and 'str'
13th Feb 2020, 7:24 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 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.
15th Feb 2020, 1:46 PM
Duncan
Duncan - avatar
+ 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
13th Feb 2020, 7:24 PM
Jianmin Chen
Jianmin Chen - avatar
0
Thanks
13th Feb 2020, 11:26 PM
Peter Emmanuel
Peter Emmanuel - avatar