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

  • Home
  • SEARCH
  • 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 6986597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:49:47+00:00 2026-05-27T18:49:47+00:00

What are the design reasons of making Python strings immutable? How does it make

  • 0
  1. What are the design reasons of making Python strings immutable? How does it make programming easier?
  2. I’m used to mutable strings, like the ones in C. How am I supposed to program without mutable strings? Are there any best practices?
  • 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-27T18:49:47+00:00Added an answer on May 27, 2026 at 6:49 pm

    When you receive a string, you’ll be sure that it stays the same. Suppose that you’d construct a Foo as below with a string argument, and would then modify the string; then the Foo‘s name would suddenly change:

    class Foo(object):
        def __init__(self, name):
            self.name = name
    
    name = "Hello"
    foo = Foo(name)
    name[0] = "J"
    

    With mutable strings, you’d have to make copies all the time to prevent bad things from happening.

    It also allows the convenience that a single character is no different from a string of length one, so all string operators apply to characters as well.

    And lastly, if strings weren’t immutable, you couldn’t reliably use them as keys in a dict, since their hash value might suddenly change.

    As for programming with immutable strings, just get used to treating them the same way you treat numbers: as values, not as objects. Changing the first letter of name would be

    name = "J" + name[1:]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any design reason for that (like the reason they gave up multi
Our design has one jvm that is a jboss/webapp (read/write) that is used to
My design exposes two kinds of resources: Images Tags I would like clients to
I'm having a hard time making a design decision I have a class in
I'm curious about this design of Javascript, and perhaps any reasons for this architecture
I'm trying to unit test a few .NET classes that (for good design reasons)
What is the rationale behind making this kind of code valid in java? Does
This isn't a show-stopping programming problem as such, but perhaps more of a design
Alright, very noob question. I'm making a CLI app that lets users design surveys.
This should be a very basic design question, but for some reason it doesn't

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.