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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:56:09+00:00 2026-05-31T11:56:09+00:00

I am confused with Python referencing. Consider the following example: My task : To

  • 0

I am confused with Python referencing. Consider the following example:

My task : To edit each element in the list

d = { 'm': [1,2,3] }
m = d['m']
m = m[1:]   # m changes its reference to the new sliced list, edits m but not d (I wanted to change d)

Similarly:

d = { 'm': [1,2,3] }
m = d['m']
m = m[0]    # As per python referencing, m should be pointing to d['m'] and should have edited d

In python everything goes by reference, then when is a new object created?
Do we always need copy and deepcopy from copy module to make object copies?

Please clarify.

  • 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-31T11:56:11+00:00Added an answer on May 31, 2026 at 11:56 am

    In Python a variable is not a box that holds things, it is a name that points to an object. In your code:

    • d = { 'm': [1,2,3] } –> binds the name d to a dictionary
    • m = d['m'] –> binds the name m to a list
    • m = m[1:] –> binds the name m to another list

    Your third line is not changing m itself, but what m is pointing to.

    To edit the elements in the list what you can do is:

    m = d['m']
    for i, item in enumerate(m):
        result = do_something_with(item)
        m[i] = result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit confused about properties in python. Consider the following code class A:
While programming with python I am often confused with the following ambiguity: should it
I'm pretty new to Python and am getting a little confused as to what
I came across a piece of python list decclaration. I am bit confused about
I'm pretty new to Python and am completely confused by .join() which I have
I am new to the python web dev world and kind of confused about
I'm new to Python, and confused by the date/time documentation. I want to compute
I'm brand new to Eclipse (learning Python). I'm really confused about the terminology within
In the Python data model reference section on slots there is a list of
I'm confused by the following behavior: Using Freebase-Python, I send a request to the

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.