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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:56:25+00:00 2026-06-08T13:56:25+00:00

I am new to Python (and dont know much about programming anyway), but I

  • 0

I am new to Python (and dont know much about programming anyway), but I remember reading that python generally does not copy values so any statement a = b makes b point to a. If I run

a = 1
b = a
a = 2
print(b)

gives the result 1. Should that not be 2?

  • 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-08T13:56:27+00:00Added an answer on June 8, 2026 at 1:56 pm

    No, the result should be 1.

    Think of the assignment operator (=) as the assignment of a reference.

    a = 1  # a references the integer object 1
    b = a  # b and a reference the same object
    a = 2  # a now references a new object (2)
    print b  # prints 1 because you changed what a references, not b
    

    This whole distinction really is most important when dealing with mutable objects such as lists as opposed to immutable objects like int, float and tuple.

    Now consider the following code:

    a = []  # a references a mutable object
    b = a   # b references the same mutable object
    b.append(1)  # change b a little bit
    print a  # [1] -- because a and b still reference the same object 
             #        which was changed via b.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm totally new to Ruby but not to programming. All I did was going
Let me start off by saying, I'm not new to programming but am very
My question does not really have much to do with sqlalchemy but rather with
I am brand new to python and don't really know too much. I am
I'm new to python so I really don't know the language very well. the
Brand new to Python (and programming in general), if this is simple and/or answered
First, I have never used SWIG, I dont know what it does... We have
So I am fairly new to python. But would like your help solving this
I know a bunch of scripting languages, (python, ruby, lua, php) but I don't
I really new to Python and coding in general, but I have been making

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.