Answer the question
In order to leave comments, you need to log in
What does this passage from the Python documentation mean?
Statement: " ...strings ... are immutable. "
Full sentence: " An object's mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable. "
I can't understand , which means " numbers and strings are immutable ". Why can't a string or number change its value?
The documentation itself
Answer the question
In order to leave comments, you need to log in
Why can't a string or number change its value?
When they say mutable / immutable, they mean the object itself in memory, and not the variable symbol that is attached to this object. If I'm not mistaken, strings and numbers are immutable in most programming languages. For example, if there is a number 10 (not a variable!, but the number itself), then its value cannot be 0, or -99, or 55.64 - it is always equal to ten, and if you need another number in the variable, then you simply equate a variable to another number. It's the same with strings. For example, if concatenation occurs, then the result of the concatenation is a completely new object in memory, which you already assign to some variable. Those. any operations on strings produce new string objects in memory.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question