start = [0,0,0,0,0,0,0,0,0]
def print_board(turn, board):
    print(turn + " turn" + "\n   {}{}{}\n   {}{}{}\n   {}{}{}".format(board))
current_turn = "your"
print_board(current_turn, start)

The above stuff gives
Traceback (most recent call last):
  File "so.py", line 5, in <module>
    print_board(current_turn, start)
  File "so.py", line 3, in print_board
    print(turn + " turn" + "\n   {}{}{}\n   {}{}{}\n   {}{}{}".format(x for x in board))
IndexError: tuple index out of range

我的元组或列表中有9个值,还有9个大括号。对吗?

最佳答案

。但是你可以很容易地通过改变:

"...".format(board)

to:
"...".format(*board)

星号format将导致列表元素作为单个参数传递。

关于python - 元组索引超出范围python,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47103483/

10-12 18:27