Re: how are strings immutable in python?

2008-07-08 Thread Lie
On Jul 7, 1:45 am, ssecorp <[EMAIL PROTECTED]> wrote: > >>> h = "aja baja" # 'aja baja' is created and assigned to the name h > >>> h += 'e' # Is the equivalent of: # h = h + 'e' # # In there, a h and 'e' is concatenated and assigned to # a new string object which is bound to h. The # original str

Re: how are strings immutable in python?

2008-07-06 Thread Martin v. Löwis
> so why would you ever want mutability? > > > seems very counterintuitive and unreliable. For lists, mutability is fairly natural. Suppose you have a function f that copies some items from one list to another. You write it as def f(src, dst): for x in src: if condition(x):

RE: how are strings immutable in python?

2008-07-06 Thread Delaney, Timothy (Tim)
ssecorp wrote: > so why would you ever want mutability? > > > seems very counterintuitive and unreliable. Because immutability imposes a lot of restrictions and performance characteristics that mutable objects don't have. For example, compare building up a list and a tuple element-by-element (u

Re: how are strings immutable in python?

2008-07-06 Thread ssecorp
so why would you ever want mutability? seems very counterintuitive and unreliable. -- http://mail.python.org/mailman/listinfo/python-list

Re: how are strings immutable in python?

2008-07-06 Thread Mark Tolonen
"ssecorp" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] so if strings were mutable and i did a = b = "foo" and then did a += "bar" then a and b would be foobar? This can be demonstrated with a list of characters, which *is* mutable: a = b = list('foo') a += list('bar') a ['f'

Re: how are strings immutable in python?

2008-07-06 Thread ssecorp
so if strings were mutable and i did a = b = "foo" and then did a += "bar" then a and b would be foobar? -- http://mail.python.org/mailman/listinfo/python-list

Re: how are strings immutable in python?

2008-07-06 Thread Terry Reedy
Peter Otten wrote: ssecorp wrote: h = "aja baja" h += 'e' h 'aja bajae' The inplace-add operator doesn't mutate the lvalue, it just rebinds it: In Python, neither '=' nor members of the 'op=' family are operators. They all mark *assignment* or *augmented assignment* statements that *all

Re: how are strings immutable in python?

2008-07-06 Thread Mel
ssecorp wrote: h = "aja baja" h += 'e' h > 'aja bajae' What Peter said, or, to put it another way: Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = b = "

Re: how are strings immutable in python?

2008-07-06 Thread Peter Otten
ssecorp wrote: h = "aja baja" h += 'e' h > 'aja bajae' The inplace-add operator doesn't mutate the lvalue, it just rebinds it: >>> a = b = "foo" >>> id(a) 47643036142016 >>> a += "bar" >>> id(a), a (47643036142064, 'foobar') >>> id(b), b (47643036142016, 'foo') Peter -- http