首页 > 解决方案 > 为什么我不能将两个变量附加为元组

问题描述

list = []
tuples = ((0,1),(1,1),(2,2),)
x = 0
y = 2
list.append([[], tuples + (x,y)])
print(list)

我使用此代码作为井字游戏 AI 的一部分来构造一棵树,但是当将此新列表附加到主列表时,元组值读取为 ((0,1),(1,1),(2,2), 0,2)。我打算将 x 和 y 变量作为单个元组的一部分,如下所示:((0,1),(1,1),(2,2),(0,2)) 我在这里做错了什么? 先感谢您

标签: pythonlisttuples

解决方案


list = []
tuples = ((0,1),(1,1),(2,2),)
x = 0
y = 2
list.append([[], tuples + ((x,y),)])
print(list)

推荐阅读