append on lists
Grant Edwards
grante at visi.com
Tue Sep 16 09:47:04 EDT 2008
On 2008-09-16, Armin <a at nospam.org> wrote:
> John Machin wrote:
>> On Sep 16, 6:45 am, Armin <a... at nospam.org> wrote:
>>
>>> Yes, but this is very unconvenient.
>>> If d should reference the list a extended with a single list element
>>> you need at least two lines
>>>
>>> a.append(7)
>>> d=a
>>>
>>> and not more intuitive d = a.append(7)
>>
>> Methods/functions which return a value other than the formal None and
>> also mutate their environment are "a snare and a delusion". Don't wish
>> for them.
>
>
>
> c = [9,10]
> [1,2,3,4,7].append(c) -> Is this a valid expression?
Yes.
> The 'value' of that expression is None.
Correct.
> However ... that's the way of the implementation of the
> append method. It's a little bit confusing to me ...
No, that's a way of calling the append method of a list. The
fact that you don't have a name bound to that list doesn't
change the fact that the list is mutable and you appended
[9,10] to it.
--
Grant Edwards grante Yow! Are the STEWED PRUNES
at still in the HAIR DRYER?
visi.com
More information about the Python-list
mailing list