Re: Clarification on Immutability please

2020-01-28 Thread Chris Angelico
On Wed, Jan 29, 2020 at 1:50 AM Random832 wrote: > > On Wed, Jan 22, 2020, at 02:34, Stephen Tucker wrote: > > Oh dear, I am sorry. I have created quite a storm. > > > > Moreover, I am sorry because I misremembered what I had typed into Idle. My > > original tuple only had two elements, not three,

Re: Clarification on Immutability please

2020-01-28 Thread Random832
On Wed, Jan 22, 2020, at 02:34, Stephen Tucker wrote: > Oh dear, I am sorry. I have created quite a storm. > > Moreover, I am sorry because I misremembered what I had typed into Idle. My > original tuple only had two elements, not three, so the slicing [:2] didn't > affect the tuple at all - and s

Re: Clarification on Immutability please

2020-01-28 Thread Chris Angelico
On Tue, Jan 28, 2020 at 9:33 PM Daniel Haude wrote: > > Am 27.01.2020 15:23 schrieb Chris Angelico: > > > The way execution works in Python, you first evaluate the object, then > > assign it to the target. The new object HAS to exist before the old > > one is replaced. There's no such thing as "at

Re: Clarification on Immutability please

2020-01-28 Thread Daniel Haude
Am 27.01.2020 15:23 schrieb Chris Angelico: The way execution works in Python, you first evaluate the object, then assign it to the target. The new object HAS to exist before the old one is replaced. There's no such thing as "atomic reassignment" that simultaneously destroys the old object and a

Re: Clarification on Immutability please

2020-01-27 Thread Chris Angelico
On Tue, Jan 28, 2020 at 2:44 AM Souvik Dutta wrote: > > If the two objects have the same value that means that when called all of > them will point to the same object rather than creating the same value - > object pairs twice. Immutability is the characteristics that does not let you > change t

Re: Clarification on Immutability please

2020-01-27 Thread Chris Angelico
On Tue, Jan 28, 2020 at 1:13 AM Musbur wrote: > > Am 21.01.2020 19:38 schrieb Chris Angelico: > > Are you sure that it does? I can't reproduce this. When you slice the > > first two from a tuple, you create a new tuple, and until the > > assignment happens, both the new one and the original coexis

Re: Clarification on Immutability please

2020-01-27 Thread Musbur
Am 21.01.2020 19:38 schrieb Chris Angelico: On Wed, Jan 22, 2020 at 4:42 AM Stephen Tucker wrote: and even that the first id(mytup) returns the same address as the second one, I am left wondering exactly what immutability is. Let's look at id()'s documentation: id(object) Return the

Re: Clarification on Immutability please

2020-01-22 Thread Richard Damon
On 1/21/20 8:41 PM, Jon Ribbens via Python-list wrote: Whether we call the link between 'foo' and (1, 2) a pointer or a reference is almost entirely irrelevant, the difference is essentially meaningless. The issue is that in Python, objects and names are fairly distinct. Unlike a language like

Re: Clarification on Immutability please

2020-01-22 Thread Eryk Sun
On 1/21/20, Jon Ribbens via Python-list wrote: > > Whether we call the link between 'foo' and (1, 2) a pointer or a > reference is almost entirely irrelevant, the difference is essentially > meaningless. In programming terms, a "pointer" is always an address in memory, and, at least to me, the te

Re: Clarification on Immutability please

2020-01-21 Thread Stephen Tucker
Oh dear, I am sorry. I have created quite a storm. Moreover, I am sorry because I misremembered what I had typed into Idle. My original tuple only had two elements, not three, so the slicing [:2] didn't affect the tuple at all - and so the second id() gave the same address as the first one. So, y

Re: Clarification on Immutability please

2020-01-21 Thread Michael Torrie
On 1/21/20 6:52 PM, Ethan Furman wrote: > On 01/21/2020 10:55 AM, Michael Torrie wrote: > >> Slicing >> returns a new object whether one is slicing a tuple, list, or a string, >> the latter two are mutable objects. > > Strings are not mutable. Yup I got my items in the wrong order. I meant to sa

Re: Clarification on Immutability please

2020-01-21 Thread MRAB
On 2020-01-22 01:52, Ethan Furman wrote: On 01/21/2020 10:55 AM, Michael Torrie wrote: Slicing returns a new object whether one is slicing a tuple, list, or a string, the latter two are mutable objects. Strings are not mutable. In the case of tuples and strings, if the slicing encompasses th

Re: Clarification on Immutability please

2020-01-21 Thread Ethan Furman
On 01/21/2020 10:55 AM, Michael Torrie wrote: Slicing returns a new object whether one is slicing a tuple, list, or a string, the latter two are mutable objects. Strings are not mutable. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list

Re: Clarification on Immutability please

2020-01-21 Thread Jon Ribbens via Python-list
On 2020-01-21, Chris Angelico wrote: > On Wed, Jan 22, 2020 at 8:01 AM Jon Ribbens via Python-list > wrote: >> On 2020-01-21, Chris Angelico wrote: >> > On Wed, Jan 22, 2020 at 4:42 AM Stephen Tucker >> > wrote: >> >> I am left concluding that mytup is not actually a tuple (even though type >>

Re: Clarification on Immutability please

2020-01-21 Thread Cameron Simpson
On 22Jan2020 09:15, Cameron Simpson wrote: It doesn't say anything about the contents of the internal objects: >>> mytup = (1, [2, 3], (4, 5)) [...] >>> mytupl[1] = [7, 8] Traceback (most recent call last): File "", line 1, in NameError: name 'mytupl' is not defined Please igno

Re: Clarification on Immutability please

2020-01-21 Thread Cameron Simpson
On 21Jan2020 17:40, Stephen Tucker wrote: I am sure this has been answered many times before, but I need to ask it again. Given that the following is valid Python 2.7.10 (when keyboarded into Idle): mytup = ("q", "w", "e") id(mytup) mytup = mytup [:2] id(mytup) and even that the first id(myt

Re: Clarification on Immutability please

2020-01-21 Thread Chris Angelico
On Wed, Jan 22, 2020 at 8:01 AM Jon Ribbens via Python-list wrote: > > On 2020-01-21, Chris Angelico wrote: > > On Wed, Jan 22, 2020 at 4:42 AM Stephen Tucker > > wrote: > >> I am left concluding that mytup is not actually a tuple (even though type > >> (mytup) tells me that it is). > > > > If

Re: Clarification on Immutability please

2020-01-21 Thread Jon Ribbens via Python-list
On 2020-01-21, Chris Angelico wrote: > On Wed, Jan 22, 2020 at 4:42 AM Stephen Tucker wrote: >> I am left concluding that mytup is not actually a tuple (even though type >> (mytup) tells me that it is). > > If type(mytup) is tuple, then mytup really truly is a tuple. There is > no other conclusio

Re: Clarification on Immutability please

2020-01-21 Thread Chris Angelico
On Wed, Jan 22, 2020 at 5:56 AM Michael Torrie wrote: > > On 1/21/20 11:38 AM, Chris Angelico wrote: > > Are you sure that it does? I can't reproduce this. When you slice the > > first two from a tuple, you create a new tuple, and until the > > assignment happens, both the new one and the original

Re: Clarification on Immutability please

2020-01-21 Thread Michael Torrie
On 1/21/20 11:38 AM, Chris Angelico wrote: > Are you sure that it does? I can't reproduce this. When you slice the > first two from a tuple, you create a new tuple, and until the > assignment happens, both the new one and the original coexist, which > means they MUST have unique IDs. And furthermo

Re: Clarification on Immutability please

2020-01-21 Thread Chris Angelico
On Wed, Jan 22, 2020 at 4:42 AM Stephen Tucker wrote: > > Hi Python-list folk, > > I am sure this has been answered many times before, but I need to ask it > again. > > Given that the following is valid Python 2.7.10 (when keyboarded into Idle): > > mytup = ("q", "w", "e") > id(mytup) > mytup = my

Clarification on Immutability please

2020-01-21 Thread Stephen Tucker
Hi Python-list folk, I am sure this has been answered many times before, but I need to ask it again. Given that the following is valid Python 2.7.10 (when keyboarded into Idle): mytup = ("q", "w", "e") id(mytup) mytup = mytup [:2] id(mytup) and even that the first id(mytup) returns the same add