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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:11:14+00:00 2026-05-18T03:11:14+00:00

I know that variable assignment in python is in fact a binding / re-bindign

  • 0

I know that “variable assignment” in python is in fact a binding / re-bindign of a name (the variable) to an object.

This brings the question: is it possible to have proper assignment in python, eg make an object equal to another object?

I guess there is no need for that in python:

  1. Inmutable objects cannot be ‘assigned to’ since they can’t be changed

  2. Mutable objects could potentially be assigned to, since they can change, and this could be useful, since you may want to manipulate a copy of dictionary separately from the original one. However, in these cases the python philosophy is to offer a cloning method on the mutable object, so you can bind a copy rather than the original.

So I guess the answer is that there is no assignment in python, the best way to mimic it would be binding to a cloned object

I simply wanted to share the question in case I’m missing something important here

Thanks

EDIT:

Both Lie Ryan and Sven Marnach answers are good, I guess the overall answer is a mix of both:

For user defined types, use the idiom:

a.dict = dict(b.dict)

(I guess this has problems as well if the assigned class has redefined attribute access methods, but lets not be fussy :))

For mutable built-ins (lists and dicts) use the cloning / copying methods they provide (eg slices, update)

finally inmutable built-ins can’t be changed so can’t be assigned

I’ll choose Lie Ryan because it’s an elegant idiom that I hadn’t thought of.

Thanks!

  • 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-18T03:11:15+00:00Added an answer on May 18, 2026 at 3:11 am

    This brings the question: is it
    possible to have proper assignment in
    python, eg make an object equal to
    another object?

    Yes you can:

    a.__dict__ = dict(b.__dict__)
    

    will do the default assignment semantic in C/C++ (i.e. do a shallow assignment).

    The problem with such generalized assignment is that it never works for everybody. In C++, you can override the assignment operator since you always have to pick whether you want a fully shallow assignment, fully deep assignment, or any shade between fully deep copy and fully shallow copy.

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

Sidebar

Related Questions

I need to know a correct name for this cool feature that some languages
How many possible combinations of the variables a,b,c,d,e are possible if I know that:
I wish to do simultaneous variable assignment in Pascal. As far as I know,
I know that using generic in an assignment, a method can implicitly know the
Okay, I know this is a common enough question, but all the solutions I've
I know that each programming language has certain guideline and styles. My question is
Had an interesting experience with Python's file buffering and wanted to know that I
I know that I can do something like $int = (int)99; //(int) has a
I know that default cron's behavior is to send normal and error output to
I know that you can insert multiple rows at once, is there a way

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.