1
raptium 2017-07-26 20:42:34 +08:00 via iPhone
不要把一个 mutable 的对象作为参数默认值
|
2
Readme16 2017-07-26 21:19:25 +08:00
Python 中的可变对象和不可变对象 https://stackoverflow.com/questions/986006/how-do-i-pass-a-variable-by-reference
|
4
lxy 2017-07-26 21:44:14 +08:00
Default parameter values are evaluated from left to right when the function definition is executed. This means that the expression is evaluated once, when the function is defined, and that the same “ pre-computed ” value is used for each call. This is especially important to understand when a default parameter is a mutable object...
https://docs.python.org/3/reference/compound_stmts.html |
5
zhanglintc 2017-07-26 23:54:00 +08:00
感觉学到了一点黑科技
|
6
NoAnyLove 2017-07-27 00:19:48 +08:00
这是一个经典错误,很多靠谱的 Python 书上都会讲解这个问题
|
7
nongmei 2017-07-27 10:42:26 +08:00
可变对象和不可变对象的区别
|
8
zhusimaji 2017-07-27 18:37:26 +08:00 via iPhone
千万不要把可变对象放在参数中
|