A question on modification of a list via a function invocation

Mok-Kong Shen mok-kong.shen at t-online.de
Wed Aug 16 17:06:49 EDT 2017


Am 15.08.2017 um 20:47 schrieb Larry Hudson:
[snip]
>> ===============  test2() code  ==============
>> def test2(alist):           ss ─┬─> [1, 2, 3]
>>                           alist ─┘
>> ---------------------------------------------
>>      <assignment>           ss ─┬─> [3, 6, 9]
>>                          alist ─┘
>> ---------------------------------------------
>>      alist = [30, 60, 90]    ss ───> [3, 6, 9]
>>                           alist ───> [30, 60, 90]
[snip]

The above shows that with <assignment>, i.e. assigning single values to
individual members of alist (with alist[0]=3 etc.) is "principally"
different from assigning a whole list to alist (with alist=[30,60,90]).
The first operation doesn't affect the connection between ss and alist,
while the second separates the connection between ss and alist, as your
diagram above clearly indicates.

Isn't this kind of convention/rule something that appears to be not
quite natural/"logical" to the common users (non-experts)?

M. K. Shen





More information about the Python-list mailing list