回答編集履歴

1

追記

2021/12/19 09:38

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -6,6 +6,10 @@
6
6
 
7
7
  for i in range(2):
8
8
 
9
- b.append(tk.Button(root, text=str(i), command=lambda i=i:print(i)))
9
+ b.append(tk.Button(root, text=str(i), command=lambda i=i: print(i)))
10
10
 
11
11
  ```
12
+
13
+
14
+
15
+ **参考**: [ループの中で異なる値で定義されたラムダ式が、同じ値を返すのはなぜですか?](https://docs.python.org/ja/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result)