This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xgyan
Recipients xgyan
Date 2018-06-11.15:42:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1528731739.92.0.592728768989.issue33835@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-06-11 15:42:19xgyansetrecipients: + xgyan
2018-06-11 15:42:19xgyansetmessageid: <1528731739.92.0.592728768989.issue33835@psf.upfronthosting.co.za>
2018-06-11 15:42:19xgyanlinkissue33835 messages
2018-06-11 15:42:19xgyancreate