close

[Solved] Unsupported operand type(s) for +: ‘int’ and ‘str’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Unsupported operand type(s) for +: ‘int’ and ‘str’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Unsupported operand type(s) for +: ‘int’ and ‘str’ Error Occurs?

Today I get the following error Unsupported operand type(s) for +: ‘int’ and ‘str’ in python.

How To Solve Unsupported operand type(s) for +: ‘int’ and ‘str’ Error ?

  1. How To Solve Unsupported operand type(s) for +: 'int' and 'str' Error ?

    To Solve Unsupported operand type(s) for +: 'int' and 'str' Error Change print(numlist.pop(2)+" has been removed") to any of these:

  2. Unsupported operand type(s) for +: 'int' and 'str'

    To Solve Unsupported operand type(s) for +: 'int' and 'str' Error Change print(numlist.pop(2)+" has been removed") to any of these:

Solution 1

You’re trying to concatenate a string and an integer, which is incorrect.

Change print(numlist.pop(2)+" has been removed") to any of these:

Explicit int to str conversion:

print(str(numlist.pop(2)) + " has been removed")

Use , instead of +:

print(numlist.pop(2), "has been removed")

String formatting:

print("{} has been removed".format(numlist.pop(2)))

Solution 2


try,

str_list = " ".join([str(ele) for ele in numlist])

this statement will give you each element of your list in string format

print("The list now looks like [{0}]".format(str_list))

and,

change print(numlist.pop(2)+" has been removed") to

print("{0} has been removed".format(numlist.pop(2)))

as well.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read