如何停止python format()中的重复

时间:2019-09-03 07:47:45

标签: python format

我有一个字符串如下:

”这1只是1,而1只是一个数字。 1 +1等于2”

当我想使用python格式时,它将类似于:

var = 1
test = "This {} is just a {} and {} is just a number. And {} + {} is equal to 2".format(var,var,var,var,var)

但是我想知道python中是否可以快速替换str.format()以避免重复。像这样:

test = "This {} is just a {} and {} is just a number. And {} + {} is equal to 2".format(var*)

0 个答案:

没有答案