[issue33835] Too strong side effect?

2018-06-11 Thread X. Yan
X. Yan added the comment: I see. Thanks for the detailed explanations. Best, Xiaogang On 6/11/2018 2:00 PM, Steven D'Aprano wrote: > Steven D'Aprano added the comment: > > Both names "v1" and "v2" refer to the same object. Python does not make > copies of objects on assignment, so if you

[issue33835] Too strong side effect?

2018-06-11 Thread R. David Murray
Change by R. David Murray : -- status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https:/

[issue33835] Too strong side effect?

2018-06-11 Thread Steven D'Aprano
Steven D'Aprano added the comment: Both names "v1" and "v2" refer to the same object. Python does not make copies of objects on assignment, so if you write: a = [] b = a then a and b both refer to the same list object, and the names "a" and "b" are effectively aliases. This is standard obje

[issue33835] Too strong side effect?

2018-06-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: See https://docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x . -- ___ Python tracker ___ ___

[issue33835] Too strong side effect?

2018-06-11 Thread X. Yan
X. Yan added the comment: Hi Serhiy, Thanks for your reply. However, the issue I reported was not about sharing the default value. I understand that the parameter L would keep its value [1] from function f's first run, and used it in the second run to get [1, 2]. My point is that the variab

[issue33835] Too strong side effect?

2018-06-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: See https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects . -- nosy: +serhiy.storchaka resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python track

[issue33835] Too strong side effect?

2018-06-11 Thread X. Yan
New submission from X. Yan : I am familiar with quite a few languages such as C++, C, PASCAL, Matlab, etc., but starting to practice Python. When I tested the code: def f(a, L=[]): L.append(a) return L followed by calls as follows, v1 = f(1) v2 = f(2) , to my surprise, I saw