<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="Osso Notes">
<title></title></head>
<body>
<p>On Mon, 24 Oct 2011, 20:04:20 CEST, Johan Martinez <<a href="mailto:jmartiee@gmail.com">jmartiee@gmail.com</a>> wrote:
<br>
<br>> I am struggling to understand Python string immutability. I am able to
<br>> modify Python string object after initializing/assigning it a value. So
<br>> how does immutability work? I am not following it. Sorry for really
<br>> stupid question. Any help?
<br>
<br>Mutibility means changinging the object (string) in place. What you are doing below is creating a new string and asigning it to a variable.
<br> 
<br>> <code>
<br>>
<br>> > > > s = "First"
<br>> > > > print s.__class__
<br>> <type 'str'>
<br>> > > > print s
<br>> First
<br>> > > > s = "Second"
<br>> > > > print s
<br>> Second
<br>> > > >
<br>>
<br>> </code>
<br>
<br>If the object s reffernces is mutable you should be able to do:
<br>
<br>s[0] = 'x'
<br>
<br>Try it and see what happen. Then also try this with a list of strings
<br>
<br>s = ['f', 'i', 'r', 's', 't']
<br>s[0] = 'x'
<br>
<br>Greets
<br>sander</p>
</body>
</html>