256 Kilobytes

Answers in Scripting and Automation | By Some Guy

Published

3,508 views, 0 RAMs, and 2 comments

Tags: Python, Scripting, Errors, Programming, TypeError

Profile Photo - Some GuySome GuyBasic Subscriber

I was working on a code on Python last night when I came across an error: "TypeError: can only concatenate str (not "int") to str". I do understand that the error is closely related to the variable types but I don't know I can fix it. Any help/suggestions is highly appreciated.

Download more RAM. 🐏 ⨉ 0Posted by Some Guy 2 years ago 🕓 Posted at 13 January, 2019 05:45 AM PST

This is a debug account.

Profile Photo - roxbladeroxbladeIndiaAuthor

You are trying to cocatenate an int with a string. And you understand that much. Different data types cannot be cocatenated. So, what you need to do is convert.

Python cannot do it automatically. So, you need to explicitly convert the int to a string using the str function and use that string in the argument for the cocatenation to take place successfully.

Download more RAM. 🐏 ⨉ 0Posted by roxblade 2 years ago 🕓 Posted at 07 February, 2019 02:22 AM PST

Some design is good, some design is bad, and yet some design is just full retard Comic Sans with a rainbow gradient on it.

Profile Photo - August R. GarciaAugust R. GarciaLARPing as a Sysadmi...Portland, ORSite Owner

Cast the integer to be a string.

# Probably something like this is causing the error
x    = 3
text = "whatever"

# "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
# Which is probably the same type of issues as what is causing the
# error in the thread title
print(x + text)

# This is also basically the same issue, but gives this error instead:
# "TypeError: Can't convert 'int' object to str implicitly"
print(text + x)

# Prints "3whatever"
print( str(x) + text )

See also:

Edit: Python string formatting should work as well:

x = 3
print( "The value of x is %s" % x )

Download more RAM. 🐏 ⨉ 0Posted by August R. Garcia 1 year ago

Edit History

• [2019-10-17 14:03 PDT] August R. Garcia (1 year ago)
• [2019-10-17 14:03 PDT] August R. Garcia (1 year ago)
🕓 Posted at 17 October, 2019 14:03 PM PDT

Sir, I can do you a nice SEO.

Post a New Comment

Do you like having a good time?

Register an Account

You can also login to an existing account or reset your password. All use of this site is subject to the terms of service and privacy policy.

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account

Answers— Read More

Find more related content below!