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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:53:43+00:00 2026-05-24T13:53:43+00:00

I think I’m starting to understand python, but I still have trouble with a

  • 0

I think I’m starting to understand python, but I still have trouble with a basic question. When to use copy.copy?

>>>a=5
>>>b=a
>>>a=6
>>>print b
5

Ok makes sense. But in what circumstances does saying b=a form some kind of ‘link’ between a and b such that modifying a would then modify b? This is what I don’t get about copy.copy — does every time you assign one variable to another with the equals sign just copy the value?

  • 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-05-24T13:53:44+00:00Added an answer on May 24, 2026 at 1:53 pm

    Basically, b = a points b to wherever a points, and nothing else.

    What you’re asking about is mutable types. Numbers, strings, tuples, frozensets, booleans, None, are immutable. Lists, dictionaries, sets, bytearrays, are mutable.

    If I make a mutable type, like a list:

    >>> a = [1, 2]  # create an object in memory that points to 1 and 2, and point a at it
    >>> b = a       # point b to wherever a points
    >>> a[0] = 2    # change the object that a points to by pointing its first item at 2
    >>> a
    [2, 2]
    >>> b
    [2, 2]
    

    They’ll both still point to the same item.

    I’ll comment on your original code too:

    >>>a=5     # '5' is interned, so it already exists, point a at it in memory
    >>>b=a     # point b to wherever a points
    >>>a=6     # '6' already exists in memory, point a at it
    >>>print b # b still points at 5 because you never moved it
    5
    

    You can always see where something points to in memory by doing id(something).

    >>> id(5)
    77519368
    >>> a = 5
    >>> id(a)
    77519368     # the same as what id(5) showed us, 5 is interned
    >>> b = a
    >>> id(b)
    77519368     # same again
    >>> id(6)
    77519356
    >>> a = 6
    >>> id(a)
    77519356     # same as what id(6) showed us, 6 is interned
    >>> id(b)
    77519368     # still pointing at 5.    
    >>> b
    5
    

    You use copy when you want to make a copy of a structure. However, it still will not make a copy of something that is interned. This includes integers less than 256, True, False, None, short strings like a. Basically, you should almost never use it unless you’re sure you won’t be messed up by interning.

    Consider one more example, that shows even with mutable types, pointing one variable at something new still doesn’t change the old variable:

    >>> a = [1, 2]
    >>> b = a
    >>> a = a[:1]    # copy the list a points to, starting with item 2, and point a at it
    >>> b            # b still points to the original list
    [1, 2]
    >>> a
    [1]
    >>> id(b)
    79367984
    >>> id(a)
    80533904
    

    Slicing a list (whenever you use a :) makes a copy.

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

Sidebar

Related Questions

I think that asking this might be kind of silly but I'm still wondering
I think I have a very popular problem, but not found answer for it
I think that I have a quite strange question. I am using a class
I think its a 5am brain drain, but I'm having trouble with understanding this.
I think most people here understand the importance of fully automated builds. The problem
I think this is specific to IE 6.0 but... In JavaScript I add a
I think I've got it down to the most basic case: int main(int argc,
I think I know how to handle this case, but I just want to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Think about the games like Spiral Knights and Minecraft(Which I believe both use LWJGL)

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.