Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8469787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:19:34+00:00 2026-06-10T16:19:34+00:00

Unlike in C++ or Java, whenever I have something like print "Hello " +

  • 0

Unlike in C++ or Java, whenever I have something like print "Hello " + 1, I get an error that it can’t concatenate str and int objects. Why isn’t this conversion done implicitly in Python?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:19:35+00:00Added an answer on June 10, 2026 at 4:19 pm
    print "Hello", 1
    

    The reason concatenation doesn’t work is that string objects don’t have any code in them to perform type conversion as part of their __add__() method. As for why, presumably Guido thought it would be a bad idea. The Zen of Python says “explicit is better than implicit.”

    You could write a string subclass that works this way, however:

    class MagicStr(str):
        def __add__(self, other):
            return MagicStr(str(self) + str(other))
        def __radd__(self, other):
            return MagicStr(str(other) + str(self))
        __iadd__ = __add__
    

    Of course, there’s no way to get Python to use that class for string literals or for user input, so you end up having to convert strings constantly:

     MagicStr("Hello") + 1
    

    At which point you might as well just write:

     "Hello" + str(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that Python, unlike Java, supports inheritance. But does a user class can
Unlike Java, Perl uses reference count for garbage collection. I have tried searching some
I used java after a long time and found out that unlike other languages
A web application has no make file unlike C++ or anything like that. However,
I am writing a translator, and have quite a few java String literals that
Unlike in java why c# does not have a supertype of Number for Floats,
In java document, it is said : Unlike interfaces, abstract classes can contain fields
Simply put in C and variants (unlike that wuss java with its virtual machine)
I have a data structure that is essentially key-value pairs. However unlike a dictionary
From ImmutableList javadocs: Unlike Collections.unmodifiableList(java.util.List), which is a view of a separate collection that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.