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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:07:36+00:00 2026-06-05T06:07:36+00:00

Does an immutable object in python mean that its value cannot be changed after

  • 0

Does an immutable object in python mean that its value cannot be changed after its conception?
If that is the case what will happen when we try to change its value.

Let me try to explain my doubt with an example.

For instance I initialized a String object S with value "Hello World".

S = 'Hello World'

Then I typed in the line,

S = 'Hello Human'

So when I ask the interpreter, it tells me the value of S is "Hello Human". Clearly now ‘S’ has a new value.

How did the value change? Did python destroy the old string object and created a new one with the new value? or did it just changed the value of the old object. Does this has anything to do with the fact that the string object is immutable? If so, then how do mutable objects behave?

  • 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-05T06:07:39+00:00Added an answer on June 5, 2026 at 6:07 am

    Python stopped S pointing to the the old string object and made it point to a new one

    >>> S="Hello World"
    >>> id(S)
    32386960
    >>> S="Hello Human"
    >>> id(S)
    32387008
    >>> 
    

    You can’t change immutable objects, so even when you think you muight be (eg with the += operator) you aren’t

    >>> S="Hello"
    >>> id(S)
    32386912
    >>> S+=" World"
    >>> id(S)
    32386960
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The definition of immutability states that the state of an object (its data) cannot
MDN states: primitive, primitive value A data that is not an object and does
What exactly does immutable mean - that is, what are the consequences of an
If a String object is immutable (and thus obviously cannot change its length), why
Does anyone have some code that will take a TimeZoneInfo field from .NET and
How does the name of an immutable object rebind to the result of an
I've to deal with an immutable object in scala 2.7.5, and one of its
If you're writing code that's using lots of beautiful, immutable data structures, case classes
What tools/libraries exist that will take a struct and automatically generate an immutable wrapper
It seems to me that immutable types are impossible in Javascript, or does anyone

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.