【发布时间】:2015-04-27 06:27:10
【问题描述】:
我正在尝试使用str.format() 函数以列打印矩阵。
这是出错的那一行:
>>>> "{!s:4}{!s:5}".format('j',4,3)
'j 4 '
>>>> "{!s:4}{!s:5}".format(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
>>> b
('dat', 'is')
我做错了什么?
编辑: 我想我知道问题出在哪里:我正在传递一个包含两个元素的元组,然后将其作为一个包含一个元素的元组传递给函数,即我的原始元组。因此出现这个错误。所以问题是如何将这个元组传递给格式函数......
【问题讨论】:
标签: python string tuples string.format