小编use*_*069的帖子

在 python 中使用带有 .format 的元组

使用.format()with 文本填充时,我遇到了这个错误。

我拥有的:

tuple = ('a', 'b', 'c')
text = "Hi {} hello {} ola {}"
#command I tried to run
text.format(tuple)
Run Code Online (Sandbox Code Playgroud)

我的目标输出:

 Hi a hello b ola c
Run Code Online (Sandbox Code Playgroud)

我得到的错误:

IndexError:元组索引超出范围

不知道如何解决这个问题!

python format tuples

3
推荐指数
1
解决办法
228
查看次数

标签 统计

format ×1

python ×1

tuples ×1