Anonymous user
Boston Python Workshop 3/Data types: Difference between revisions
→Strings are a lot like lists
imported>Jesstess |
imported>Jesstess |
||
Line 263:
>>> my_string
'Hello Jessica'
</pre>
* One big way in which strings are different from lists is that lists are mutable (you can change them), and strings are immutable (you can't change them). To "change" a string you have to make a copy:
<pre>
>>> h = "Hello"
>>> h[0] = "J"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>> h = "J" + h[1:]
>>> h
'Jello'
</pre>
|