首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在python中,错误"IndexError: tuple index out of range“是什么意思?

在python中,错误"IndexError: tuple index out of range“是什么意思?
EN

Stack Overflow用户
提问于 2018-06-13 08:28:44
回答 1查看 7.8K关注 0票数 -1

我试图清理我的代码,而不是在函数中使用一堆if语句。下面是我的代码:

代码语言:javascript
复制
def tic(inpinp, board, qweqwe):
    global lik 
    ink = inpinp - 1
    lik = board.insert(ink, qweqwe)


lis = ['  ', '  ', '  ', '  ', '  ', '  ',  '  ', '  ']

p = input("Player 1, would you like to be X or O?")
inpu = int(input("Where would you like to go?"))






print('{}|{}|{}'.format())
print('--|--|--'.format())
print('{}|{}|{}'.format())
print("--|--|--".format())
print('{}|{}|{}'.format())
EN

回答 1

Stack Overflow用户

发布于 2018-06-13 08:31:57

我假设您想知道为什么从上面的代码中得到一个IndexError (因为其中没有显式的tuple或索引)。

'{}|{}|{}'.format()隐含地表示'{0}|{1}|{2}'.format(),其中012 indicate indices into the positional arguments传递给format。问题是,您没有传递任何参数,所以当它使用0对参数的tuple进行索引时,它会立即失败,引发IndexError。您需要传递与您在格式字符串中提供的占位符一样多的参数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50827568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档