指定单词之间的空格

时间:2014-06-25 17:25:47

标签: python tabs

我怎么能在python中使用空格,我可以指定单词之间的间距

打印"约翰和(5个空格)马克去了(3个地方)伦敦"

如何将5个空格指定为代码而不将其键入为" "

3 个答案:

答案 0 :(得分:1)

你可以试试这个:

space = " "
print "John and{}Mark went to{}London".format(space*5,space*3)

Here you can find more information

答案 1 :(得分:0)

is there anyway to use for example \s{5} ?

我理解正确:

space = " "
print "John and %s Mark went to %s London" % (space*5,space*3)

答案 2 :(得分:0)

如果您想要模板字符串中的空格数而不是format的参数:

>>> "John and{0:5s}Mark went to{0:3s}London".format("")
'John and     Mark went to   London'