[Tutor] Replace a character by index

Andre Engels andreengels at gmail.com
Thu Jul 16 12:44:13 CEST 2009


On Thu, Jul 16, 2009 at 11:22 AM, Gregor Lingl<gregor.lingl at aon.at> wrote:

> That's simply not true in Python. Try it out!
>
>>>> word = "cat"
>>>> word[1] = "_"
> Traceback (most recent call last):
>  File "<pyshell#1>", line 1, in <module>
>   word[1] = "_"
> TypeError: 'str' object does not support item assignment

And the reason for that, undoubtedly, is that strings are immutable.


-- 
André Engels, andreengels at gmail.com


More information about the Tutor mailing list