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 8996497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:45:45+00:00 2026-06-15T23:45:45+00:00

Can anyone familiar with Python’s internals (CPython, or other implementations) explain why list addition

  • 0

Can anyone familiar with Python’s internals (CPython, or other implementations) explain why list addition is required to be homogenous:

In [1]: x = [1]

In [2]: x+"foo"
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
C:\Users\Marcin\<ipython-input-2-94cd84126ddc> in <module>()
----> 1 x+"foo"

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

In [3]: x+="foo"

In [4]: x
Out[4]: [1, 'f', 'o', 'o']

Why shouldn’t the x+"foo" above return the same value as the final value of x in the above transcript?

This question follows on from NPE’s question here: Is the behaviour of Python's list += iterable documented anywhere?

Update: I know it is not required that heterogenous += work (but it does) and likewise, it is not required that heterogenous + be an error. This question is about why that latter choice was made.

It is too much to say that the results of adding a sequence to a list are uncertain. If that were a sufficient objection, it would make sense to prevent heterogenous +=. Update2: In particular, python always delegates operator calls to the lefthand operand, so no issue “what is the right thing to do” arises”: the left-hand object always governs (unless it delegates to the right).

Update3: For anyone arguing that this is a design decision, please explain (a) why it is not documented; or (b) where it is documented.

Update4: “what should [1] + (2, ) return?” It should return a result value equal with the value of a variable x initially holding [1] immediately after x+=(2, ). This result is well-defined.

  • 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-15T23:45:46+00:00Added an answer on June 15, 2026 at 11:45 pm

    These bug reports suggest that this design quirk was a mistake.

    Issue12318:

    Yes, this is the expected behavior and yes, it is inconsistent.

    It’s been that way for a long while and Guido said he wouldn’t do it again (it’s in his list of regrets). However, we’re not going to break code by changing it (list.__iadd__ working like list.extend).

    Issue575536:

    The intent was that list.__iadd__ correspond exactly to
    list.extend(). There’s no need to hypergeneralize
    list.__add__() too: it’s a feature that people who don’t
    want to get surprised by Martin-like examples can avoid
    them by using plain + for lists.

    (Of course, there are those of us who find this behaviour quite surprising, including the developer who opened that bug report).

    (Thanks to @Mouad for finding these).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone familiar with a way how can I can i write something to the
Can anyone explain to me why this program: for(float i = -1; i <
Can anyone explain why here a = [] ? 1 : 2 a will
Can anyone, please, explain to me in very simple terms what a "method" is
Is anyone familiar with os/161 and can answer a few questions for me? How
Is anyone familiar with a framework or library that can be added to an
Can anyone please explain exactly what this code and its components are doing? I
Can anyone please explain the following to me? The following is a minimum length
Is anyone familiar with this term? Can't find much about it on the interwebs.
Can anyone familiar with the Twitter Search API tell me what the earliest possible

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.