[Tutor] Changing the value in a list

Ken G. beachkid at insightbb.com
Thu Mar 11 17:04:21 CET 2010


Okay, I understand now.  Thanks!

Ken

Steve Willoughby wrote:
> On Thu, Mar 11, 2010 at 10:32:45AM -0500, Ken G. wrote:
>   
>>    list = ['physics', 'chemistry', 1997, 2000]
>>     
>
> This is a list of 4 elements, and lists allow elements to
> be changed, so
>
>   
>>    list[2] = 2010
>>     
>
> Will change the value of list to be ['physics','chemistry',1997,2010]
>
>   
>>    line = [2010020820841134]
>>     
>
> Is this one right, or did you mean '2010020820841134'?  What is shown is
> a list of one element.  Assuming you meant it to be a string, that would
> give the error you quote below.
>
> Strings are immutable objects, meaning that once they are created you can't
> change them, although you can construct new strings from them, so if you
> wanted to make a string which had characters 9 and 10 replaced with "08"
> you could say:
>   line = line[:9]+"08"+line[11:]
>
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100311/0282e27c/attachment.html>


More information about the Tutor mailing list