- Python Text Processing - Home
- Python Text Processing - Introduction
- Python Text Processing - Environment
- Python Text Processing - String Immutability
- Python Text Processing - Sorting Lines
- Python Text Processing - Counting Token in Paragraphs
- Python Text Processing - Binary ASCII Conversion
- Python Text Processing - Strings as Files
- Python Text Processing - Backward File Reading
- Python Text Processing - Filter Duplicate Words
- Python Text Processing - Extract Emails from Text
- Python Text Processing - Extract URL from Text
- Python Text Processing - Pretty Print
- Python Text Processing - State Machine
- Python Text Processing - Capitalize and Translate
- Python Text Processing - Tokenization
- Python Text Processing - Remove Stopwords
- Python Text Processing - Synonyms and Antonyms
- Python Text Processing - Translation
- Python Text Processing - Word Replacement
- Python Text Processing - Spelling Check
- Python Text Processing - WordNet Interface
- Python Text Processing - Corpora Access
- Python Text Processing - Tagging Words
- Python Text Processing - Chunks and Chinks
- Python Text Processing - Chunk Classification
- Python Text Processing - Classification
- Python Text Processing - Bigrams
- Python Text Processing - Process PDF
- Python Text Processing - Process Word Document
- Python Text Processing - Reading RSS feed
- Python Text Processing - Sentiment Analysis
- Python Text Processing - Search and Match
- Python Text Processing - Text Munging
- Python Text Processing - Text wrapping
- Python Text Processing - Frequency Distribution
- Python Text Processing - Summarization
- Python Text Processing - Stemming Algorithms
- Python Text Processing - Constrained Search
Python Text Processing Useful Resources
Python Text Processing - String Immutability
In python, the string data types are immutable. Which means a string value cannot be updated. We can verify this by trying to update a part of the string which will led us to an error.
Checking Immutability of a String
main.py
# Can not reassign t= "Tutorialspoint" print(type(t)) t[0] = "M"
Output
When we run the above program, we get the following output −
<class 'str'>
Warnings/Errors:
Traceback (most recent call last):
File "/home/cg/root/31c1433c/main.py", line 4, in <module>
t[0] = "M"
~^^^
TypeError: 'str' object does not support item assignment
Checking Memory Location of Letters of a String
We can further verify this by checking the memory location address of the position of the letters of the string.
main.py
x = 'banana'
for idx in range (0,5):
print(x[idx], "=", id(x[idx]))
Output
When we run the above program we get the following output. As you can see above a and a point to same location. Also N and N also point to the same location.
b = 11817208 a = 11817160 n = 11817784 a = 11817160 n = 11817784
Advertisements