First a pointed to the string "Dog". Then you changed the variable a to point at a new string "Dog eats treats". You didn't actually mutate the string "Dog". Strings are immutable, variables can point at whatever they want.

Answer from Bort on Stack Overflow
๐ŸŒ
Austin Z. Henley
austinhenley.com โ€บ blog โ€บ pythonstringsaremutable.html
Python strings are immutable, but only sometimes - Austin Z. Henley
February 15, 2021 - The standard wisdom is that Python strings are immutable. You can't change a string's value, only the reference to the string. Like so: ... Which implies that each time you make a change to a string variable, you are actually producing a brand ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ what does 'strings are immutable' mean?
r/learnprogramming on Reddit: What does 'Strings are immutable' mean?
September 29, 2022 -

I'm using Treehouse for Python basics and the tutor mentions this in the context of reassigning a value to a string variable. But if the value of the string variable can be reassigned, what does it mean to say it's immutable? Is there something I'm just not getting? Thanks.

๐ŸŒ
Google
developers.google.com โ€บ google for education โ€บ python โ€บ python strings
Python Strings | Python Education | Google for Developers
String literals inside triple quotes, """ or ''', can span multiple lines of text. Python strings are "immutable" which means they cannot be changed after they are created (Java strings also use this immutable style).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ why-are-python-strings-immutable
Why are Python Strings Immutable? - GeeksforGeeks
October 13, 2025 - Strings in Python are "immutable" i.e. they cannot be changed after they are created. Strings are immutable by design to keep them safe, consistent, and efficient.
๐ŸŒ
CodeHS
codehs.com โ€บ textbook โ€บ intropython_textbook โ€บ 5.3
Textbook: Intro to Python Textbook | CodeHS
1. Python and Console Interaction ยท 2. Conditionals ยท 3. Looping ยท 4. Functions and Exceptions ยท 5. Strings ยท 5.1 Indexing ยท 5.2 Slicing ยท 5.3 Immutability ยท Immutability ยท What you CAN do ยท What you CAN'T do ยท String Immutability ยท Check Your Understanding ยท
Find elsewhere
๐ŸŒ
SCSynth
scsynth.org โ€บ questions
Why are strings immutable? - Questions - scsynth
May 17, 2024 - Iโ€™m sure that Iโ€™m missing something hereโ€ฆ but why are strings immutable. In other languages, you want immutable strings so you can intern them and making their hashes equivalent. This isnโ€™t necessary in supercollider because we have explicitly interned strings (Symbol).
๐ŸŒ
Hacker News
news.ycombinator.com โ€บ item
All strings in python are immutable, as an example. | Hacker News
July 25, 2025 - The standard library also has String, CString, CStr, OsString, and OsStr ยท The latter four are for niche situations. 99.9% of the time, it's similar to Java: &str is Java's String, String is Java's StringBuffer/StringBuilder
๐ŸŒ
Quora
quora.com โ€บ In-Python-which-data-type-is-mutable-strings-list-tuple-or-dictionary
In Python, which data type is mutable, strings, list, tuple, or dictionary? - Quora
Answer (1 of 4): In Python strings are immutable, i.e. you cannot modify an existing string in place, you must create a new string every time. Numbers (int, float, complex, decimal) are also immutable. Lists are mutable you can add and remove items from a list at will. Tuples themselves are imm...
๐ŸŒ
Physics Forums
physicsforums.com โ€บ other sciences โ€บ programming and computer science
Are Python strings truly immutable? โ€ข Physics Forums
September 23, 2022 - Another participant clarifies that in Python, variables are bindings to objects rather than direct references to memory locations, emphasizing that strings are indeed immutable as they cannot be changed in place.
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-18762.html
A mutable string??
Before I get going, I know strings aren't mutable, which is why I am perplexed. I was writing myself a simple example, to prove that strings aren't mutable, and I can't explain my results. alphabet = 'bcdefghijklmnopqrstuvwxy' print(hex(id(...
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ stdtypes.html
Built-in Types โ€” Python 3.14.6 documentation
There are three basic sequence types: lists, tuples, and range objects. Additional sequence types tailored for processing of binary data and text strings are described in dedicated sections. The operations in the following table are supported by most sequence types, both mutable and immutable.
Top answer
1 of 3
18
This really confused me at first also. Basically in your example you are reassigning the variable to a different string, not necessary changing the existing string. Notice how when you are working with a list, you can access any index and change the value that is in it. However, you cannot do that with strings. Strings are indexed liked list and you can iterate through them, but you can't change the value of a single index. For example, This is how you can change the value of a list because it is mutable. python some_list = ["this", "is", "some", "list"] print(some_list) some_list[2] = "hello" # this will change the value that is in index from 'some' to list' print(some_list) You can try to do the same with a string, but it doesn't work For example, lets try to change the the value of index 2 in a string python some_string = "This is some string" some_string[2] = "a" This will not work because strings are immutable. I hope this helps!
2 of 3
3
What does that mean exactly? You've already said exactly what it means (impossible to change), so I'll clarify: the programming language does not allow immutable values to change. A variable is like a name tag: you can stick it on whatever you please. If I reattach my name tag onto you, though, I haven't actually changed myself into you. Whether you or I have changed (eg, get a tattoo, grow a tail) is an entirely different question; the name tag has nothing to do with it. The same distinction applies between a variable and the value assigned to it. Variables (unlike values) are names that can be (re)assigned. Can we change a value itself rather than a variable assignment? This distinction matters when multiple variables are assigned to the same value. When a value itself changes, all variables assigned to it are still assigned to the updated value: no variable reassignments are needed to "propagate" the update. This differs from tracking down every single variable and reassigning its value. Consider the code python variable1 = 'string' variable2 = variable1 with both variable1 and variable2 assigned the same string value. Is it possible to update the value assigned to variable2 by only manipulating variable1? Not in python.
๐ŸŒ
Real Python
realpython.com โ€บ python-mutable-vs-immutable-types
Python's Mutable vs Immutable Types: What's the Difference? โ€“ Real Python
January 26, 2025 - Strings in Python are immutable, meaning you canโ€™t change their content after creation. To check if an object is mutable, you can try altering its contents.
๐ŸŒ
Better Programming
betterprogramming.pub โ€บ pointers-strings-and-im-mutability-680b15dd4a70
Pointers, Strings, and (im)mutability in Python | by Danny D. Leybzon | Better Programming
June 19, 2022 - Wrong! Any Python aficionado will tell you that Python strings are โ€œimmutableโ€, meaning that they canโ€™t be modified directly. Instead, when you try to modify a string, Python will create a new object in memory based on the mutation that ...
๐ŸŒ
Quora
quora.com โ€บ Is-there-a-reason-that-strings-and-tuples-are-immutable-whereas-lists-and-sets-are-mutable-in-Python-or-is-just-how-it-is
Is there a reason that strings and tuples are immutable whereas lists and sets are mutable in Python, or is just how it is? - Quora
Answer: Yes - there is a reason: Strings, tuples, integers, floats and complex numbers are immutable in Python so that they can be hashed and that hash value is constant based on their content throughout the life of the object: if you could change the value in one of these objects then the hash ...
๐ŸŒ
Kadenfrisk
python.kadenfrisk.com โ€บ strings in python โ€บ string immutability
Python String Immutability | Fluffy's Python Course
In Python, strings are immutable. This means that once a string object is created, its content cannot be changed. Any operation that appears to modify a string actually creates a new string object.
๐ŸŒ
Cleancode
cleancode.studio โ€บ python โ€บ are-python-strings-mutable
Clean Code Studio - Are Python Strings Mutable
No, Python strings are immutable, meaning that once a string has been created, its contents cannot be changed. This property of strings makes them efficient for various string processing tasks and allows for optimized string operations.