top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why are Python strings immutable? What does befits of it?

+2 votes
394 views
Why are Python strings immutable? What does befits of it?
posted Nov 30, 2014 by Amit Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

Python String are immutable. There is some advantage to have string as immutable.

First advantage is performance, knowing that a string is immutable means we can allocate space for it at creation time, and the storage requirements are fixed and unchanging. This is also one of the reasons for the distinction between tuples and lists.

Another advantage is that strings in Python are considered as "elemental" as numbers. No amount of activity will change the value 8 to anything else, and in Python, no amount of activity will change the string "eight" to anything else.

answer Dec 1, 2014 by Kali Mishra
Similar Questions
+2 votes

I'm trying to search for several strings, which I have in a .txt file line by line, on another file. So the idea is, take input.txt and search for each line in that file in another file, let's call it rules.txt.

So far, I've been able to do this, to search for individual strings:

import re
shakes = open("output.csv", "r")

for line in shakes:
 if re.match("STRING", line):
 print line,

How can I change this to input the strings to be searched from another file?

+1 vote

I want to do the Boolean search over various sentences or documents. I do not want to use special programs like Whoosh, etc.

May I use any other parser? If anybody may kindly let me know.

+1 vote

I wanted to do a little project for learning Python. I thought a chat system will be good as it isn't something that I have ever done.

I wanted to know what will I need? I think that would require me these

1 learn network/socket programming
2 find a free server to host my chat server
3 GUI development for clients

-I wanted to know whether these are all that I would need or are there more things?
-Will I need to learn a web framework like Django?
-Will I need to learn something for database management like sql for handling people's account names and password?

Is google appengine good for hosting the website or should I look up at django hosting websites?

...