[issue33835] Too strong side effect?

X. Yan report at bugs.python.org
Mon Jun 11 11:42:19 EDT 2018


New submission from X. Yan <xgyan at yorku.ca>:

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 the v1's content was changed from initial [1] to [1, 2], when the second call, v2=f(2), was executed. This means when you produce the new value for v2, you have to be very very careful for all the results produced by this function previously, such as what in the v1. They can be changed in the background! I wonder if this side-effect was designed on purpose, or is actually a BUG, because it is too dangerous.

----------
messages: 319308
nosy: xgyan
priority: normal
severity: normal
status: open
title: Too strong side effect?
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33835>
_______________________________________


More information about the Python-bugs-list mailing list