Thanks for your help. I just found a webpage used for me: http://stackoverflow.com/questions/10017147/python-replace-characters-in-string
That page provides some other solutions. Thanks! On Sun, Feb 24, 2013 at 7:47 PM, Asokan Pichai <[email protected]>wrote: > On Feb 24, 2013 4:27 PM, "Sudo Nohup" <[email protected]> wrote: > > > > Dear all, > > > > I want to change the value of a char in a string for Python. However, It > seems that "=" does not work. > > > > Could you help me? Thanks! > > > > str = "abcd" > > result = [char = 'a' for char in str if char == 'c'] > > > > > > OR: > > > > str = 'abcd' > > for char in str: > > if char == 'a': > > char = 'c' > > > > > > OR: > > > > str = 'abcd' > > for i in range(len(str)): > > if str[i] == 'a': > > str[i] = 'c' > > > > ( > > Traceback (most recent call last): > > File "<stdin>", line 3, in <module> > > TypeError: 'str' object does not support item assignment > > ) > > Look up string replace function. >
_______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
