TypeError: can only concatenate str (not “int”) to str

This error is a typeError where in python we cannot concatenate a string with an integer. So both datatype that you append should be of int or str

Code:

print("one" + 2)

Error:

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

Workaround:

Either convert the number to a string or convert string to number

--Convert number to string
print("one" + "2")


one 2


--Convert string to number
print(1+2)

3

or

print("one" + str(2))

one 2

Leave a Reply