目前,我正在尝试在 Python 中获取一个方法来返回零、一个或两个字符串的列表以插入字符串格式化程序,然后将它们传递给字符串方法。我的代码看起来像这样:
class PairEvaluator(HandEvaluator):
def returnArbitrary(self):
return ('ace', 'king')
pe = PairEvaluator()
cards = pe.returnArbitrary()
print('Two pair, {0}s and {1}s'.format(cards))
当我尝试运行此代码时,编译器会给出 IndexError: tuple index out of range。
我应该如何构造我的返回值以将其作为参数传递给.format()
?