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.
More Related Contents:
- Mutable and Immutable Strings in python
- Remove specific characters from a string in Python
- About the changing id of an immutable string
- Why are python strings and tuples are made immutable?
- Python string with space and without space at the end and immutability
- Why are Python strings immutable? Best practices for using them
- How to handle special cases in my Python code?
- How to extract the substring between two markers?
- What is the difference between a string and a byte string?
- Good Python modules for fuzzy string comparison? [closed]
- Case insensitive ‘in’
- Alphabet range in Python
- Using “and” and “or” operator with Python strings [duplicate]
- Joining pairs of elements of a list [duplicate]
- Splitting a string by list of indices
- Setting variables with exec inside a function
- Rotating strings in Python
- How can I convert a string to an int in Python?
- Python testing whether a string is one of a certain set of values [duplicate]
- Print very long string completely in pandas dataframe
- Remove duplicate chars using regex?
- Python references
- How to find out if a Python object is a string?
- Print without b’ prefix for bytes in Python 3
- Limiting Python input strings to certain characters and lengths
- Python: Best Way to remove duplicate character from string
- Deleting consonants from a string in Python
- Pandas: Modify a particular level of Multiindex
- How does str.startswith really work?
- Python string operation, extract text between html tags