[Baypiggies] string question

Alexandre Conrad alexandre.conrad at gmail.com
Tue Apr 5 22:27:59 CEST 2011


String are immutable. Convert your string to a list, edit the list,
and join back to a string.


2011/4/5 Vikram K <kpguy1975 at gmail.com>:
> Given a string and some indices, how do i change upper characters
> corresponding to some position(s) in the string to lower characters? I tried
> and failed.
>
>>>> x = 'EPSPVRYDNLSR'
>>>> z = [2, 6]
>>>> for i in z:
>     print x[i]
>
>
> S
> Y
>>>> for i in z:
>     print x[i].lower()
>
>
> s
> y
>>>> for i in z:
>     x[i] = x[i].lower()
>
>
> Traceback (most recent call last):
>   File "<pyshell#14>", line 2, in <module>
>     x[i] = x[i].lower()
> TypeError: 'str' object does not support item assignment
>
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
>



-- 
Alex | twitter.com/alexconrad


More information about the Baypiggies mailing list