[Tutor] Tuple - Immutable ?

Sudip Bhattacharya sudipb at sudipb.com
Thu Mar 8 12:41:28 CET 2012


That makes perfect sense. What happened was that the old tuple got replaced
with a new tuple (old + new items) and NOT changed cause tuple is
immutable.

Thanks HTH.

On Thu, Mar 8, 2012 at 4:53 PM, col speed <ajarncolin at gmail.com> wrote:

> On 8 March 2012 18:11, Sudip Bhattacharya <sudipb at sudipb.com> wrote:
> >>>> s=(1,2,3)
> >>>> s=s+(4,5,6)
> >>>>s
> > (1,2,3,4,5,6)
> >
> > The tuple has changed.
> >
> > I thought I read that tuples are sequences (like lists), but they are
> > immutable - They can't be changed once created. Could someone explain
> please
> > ?
>
> I'm just a noob, but as nobody else has replied yet......
> As far as I *think* I know:
> s=s+(4,5,6) creates a new tuple, it doesn't change it.
> Tuples are immutable as in you can't add or append and stuff.
> Also:
>
> >>> s[0] = 8
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: 'tuple' object does not support item assignment
> Nor does it have attribute "reverse" or anything like that.
>
> HTH
> Col
>



-- 
Thanks and regards,
Sudip Bhattacharya

Mobile: +91 9999 100 706
Home Land line: +91 11 22237561
Office Land line: +91 0124 4321078
eMail ID: sudipb at sudipb.com; sudipb at gmail.com

Please visit my website at: www.sudipb.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120308/6bb99890/attachment-0001.html>


More information about the Tutor mailing list