Re: [Tutor] string immutability

2011-10-25 Thread Steven D'Aprano
On Tue, Oct 25, 2011 at 12:56:56AM +0100, Alan Gauld wrote: > On 24/10/11 20:52, Johan Martinez wrote: > >Finally I figured it out ( __length__() ) thanks to ipython shell env. > > len(x) > > gets converted to x.__length__() by Python. That's actually __len__ not __length__. >>> [].__length__

Re: [Tutor] string immutability

2011-10-24 Thread Alan Gauld
On 24/10/11 20:52, Johan Martinez wrote: Also, is there any doc link where I can find all the information about String object - class and instance methods. >>> help(str) or even >>> help("") For a quick list try dir() >>> dir ("") Finally I figured it out ( __length__() ) thanks to ipy

Re: [Tutor] string immutability

2011-10-24 Thread Joel Goldstick
the len() function works on lots of objects: >>> a = "this is a string" >>> len(a) 16 On Mon, Oct 24, 2011 at 3:52 PM, Johan Martinez wrote: > > > On Mon, Oct 24, 2011 at 2:32 PM, Steve Willoughby wrote: > >> On 24-Oct-11 12:17, Johan Martinez wrote: >> >>> Thanks for the replies everyone - St

Re: [Tutor] string immutability

2011-10-24 Thread Johan Martinez
On Mon, Oct 24, 2011 at 2:32 PM, Steve Willoughby wrote: > On 24-Oct-11 12:17, Johan Martinez wrote: > >> Thanks for the replies everyone - Steve, Dave, Sander and Wayne. I >> realized my wrong understanding/interpretation after posting the message >> to the list, which usually happens most of t

Re: [Tutor] string immutability

2011-10-24 Thread Dave Angel
On 10/24/2011 03:21 PM, Johan Martinez wrote: On Mon, Oct 24, 2011 at 2:07 PM, Andreas Perstinger< andreas.perstin...@gmx.net> wrote: On 2011-10-24 20:04, Johan Martinez wrote: Hi, I am struggling to understand Python string immutability. I am able to modify Python string object after initi

Re: [Tutor] string immutability

2011-10-24 Thread Steve Willoughby
On 24-Oct-11 12:17, Johan Martinez wrote: Thanks for the replies everyone - Steve, Dave, Sander and Wayne. I realized my wrong understanding/interpretation after posting the message to the list, which usually happens most of the time with me! That happens to most of us all the time too :) Unf

Re: [Tutor] string immutability

2011-10-24 Thread Dipo Elegbede
What you did here is just re-assigning s. Try slicing s and then assign a new value to the slice. s[2] would return 'r' now try to to set s[2] to another value to understand immutability. Hope it helps. On 24 Oct 2011 19:06, "Johan Martinez" wrote: > Hi, > > I am struggling to understand Python

Re: [Tutor] string immutability

2011-10-24 Thread Johan Martinez
On Mon, Oct 24, 2011 at 2:07 PM, Andreas Perstinger < andreas.perstin...@gmx.net> wrote: > On 2011-10-24 20:04, Johan Martinez wrote: > >> Hi, >> >> I am struggling to understand Python string immutability. I am able to >> modify Python string object after initializing/assigning it a value. >> >>

Re: [Tutor] string immutability

2011-10-24 Thread Johan Martinez
On Mon, Oct 24, 2011 at 1:52 PM, Wayne Werner wrote: > On Mon, Oct 24, 2011 at 1:04 PM, Johan Martinez wrote: > >> Hi, >> >> I am struggling to understand Python string immutability. I am able to >> modify Python string object after initializing/assigning it a value. So how >> does immutability wo

Re: [Tutor] string immutability

2011-10-24 Thread Andreas Perstinger
On 2011-10-24 20:04, Johan Martinez wrote: Hi, I am struggling to understand Python string immutability. I am able to modify Python string object after initializing/assigning it a value. s = "First" print s.__class__ print s First s = "Second" print s Second Dave, Sander and Wayne

Re: [Tutor] string immutability

2011-10-24 Thread Steve Willoughby
On Mon, Oct 24, 2011 at 01:04:20PM -0500, Johan Martinez wrote: > Hi, > > I am struggling to understand Python string immutability. I am able to > modify Python string object after initializing/assigning it a value. So how > does immutability work? I am not following it. Sorry for really stupid >

Re: [Tutor] string immutability

2011-10-24 Thread Wayne Werner
On Mon, Oct 24, 2011 at 1:04 PM, Johan Martinez wrote: > Hi, > > I am struggling to understand Python string immutability. I am able to > modify Python string object after initializing/assigning it a value. So how > does immutability work? I am not following it. Sorry for really stupid > question

Re: [Tutor] string immutability

2011-10-24 Thread Sander Sweers
On Mon, 24 Oct 2011, 20:04:20 CEST, Johan Martinez wrote: > I am struggling to understand Python string immutability. I am able to > modify Python string object after initializing/assigning it a value. So > how does immutability work? I am not following it. Sorry for really > stupid question. Any

Re: [Tutor] string immutability

2011-10-24 Thread Dave Angel
On 10/24/2011 02:04 PM, Johan Martinez wrote: Hi, I am struggling to understand Python string immutability. I am able to modify Python string object after initializing/assigning it a value. So how does immutability work? I am not following it. Sorry for really stupid question. Any help? You're c