回答編集履歴
3
参考のリンク追加
test
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Python公式ドキュメントのよくある質問に書いてあります。
|
2
2
|
https://docs.python.org/ja/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result
|
3
3
|
|
4
|
-
引数のデフォルト値を
|
4
|
+
[引数のデフォルト値が定義時に評価される](https://docs.python.org/ja/3/faq/programming.html#why-are-default-values-shared-between-objects)ことを利用して
|
5
5
|
```python
|
6
6
|
func_list = []
|
7
7
|
|
2
説明
test
CHANGED
@@ -18,4 +18,4 @@
|
|
18
18
|
```pyhton
|
19
19
|
func_list.append(lambda x=i: print(x))
|
20
20
|
```
|
21
|
-
と書くのがいいです。
|
21
|
+
と変数名を別にして書くのがいいです。
|
1
些細
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Pythonのよくある質問に書いてあります。
|
1
|
+
Python公式ドキュメントのよくある質問に書いてあります。
|
2
2
|
https://docs.python.org/ja/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result
|
3
3
|
|
4
4
|
引数のデフォルト値を使って
|