【发布时间】:2021-03-07 20:36:22
【问题描述】:
我似乎遇到了问题 pythons .format() 工具。我目前有这个代码:
varno=6
input=product([True,False],repeat = (varno))
string= ({1} or not {2} or not {5} )and (not {1} or {6} )and (not {2} or not {3} )and ({3} or not {4} )and (not {4} or {5} or not {6} )
for i in input:
print(i) //prints (True, True, True, True, True, True)
ans=(string.format(*i))
它会返回这个错误
ans=(string.format(*i))
IndexError: Replacement index 6 out of range for positional args tuple
即使 i 中有 6 个值,所以 6 不应该超出范围。我不知道出了什么问题或如何解决它。任何帮助将不胜感激。
【问题讨论】:
标签: python loops indexing format