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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s