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

  • Home
  • SEARCH
  • 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 8807655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:25:17+00:00 2026-06-14T02:25:17+00:00

Possible Duplicate: What does plus equals (+=) do in Python? I noticed a strange

  • 0

Possible Duplicate:
What does plus equals (+=) do in Python?

I noticed a strange problem:

    l1 = ['1', '2', '3']
    l2 = l1

    item = l2.pop(0)
    # the pop operation will effect l1
    print l1

    l2 = l2 + [item]
    # why "l2 = l2 + [item]" does't effect l1 while "l2 += [item]" does.
    print l2
    print l1

The output is:

['2', '3']
['2', '3', '1']
['2', '3']

But if i change l2 = l2 + [item] into l2 += [item], the output will be:

['2', '3']
['2', '3', '1']
['2', '3', '1']
  • 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-14T02:25:18+00:00Added an answer on June 14, 2026 at 2:25 am

    + and += are different operators woth different internal meaning as described here.

    l2 = l1 + x calls l2 = l1.__add__(x), if that doesn’t work it calls x.__radd__(l1). Both should return a new object forming the result of the operation, independent from the old one, thus not affecting l1.

    l2 += x calls l2 = l2.__iadd__(x) (“augmented assignment”), and only if this doesn’t work, falls back to l2 = l2 + x as described above.

    With numbers, both are the same, because they are immutable and thus cannot be modified with +=, while on lists, + returns a new object while += modifies the left hand side one.

    As the object behind l2 is modified and l1 refers the same object, you notice the change on l1 as well.

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

Sidebar

Related Questions

Possible Duplicate: What does += (plus equals) mean? What is the point of sum
Possible Duplicate: What's the difference between *:80 and +:80 What does the plus sign
Possible Duplicate: Does $_REQUEST have security problem? Does anyone have verifiable citations on this?
Possible Duplicate: Does the compiler continue evaluating an expression where all must be true
Possible Duplicate: Does anyone know of a good C# API for Subversion? I'm designing
Possible Duplicate: Does fast enumeration in Objective-C guarantee the order of iteration? Just a
Possible Duplicate: How does this CSS triangle shape work? Please help me i need
Possible Duplicate: What does “(void) new” mean in C++? I'm not familiar with C++
Possible Duplicate: Why does the background of TextView change it's size? I have a
Possible Duplicate: What does the question mark and the colon (?: ternary operator) mean

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.