Specifying spaces between words

可紊 提交于 2019-12-12 02:03:42

问题


how could I use whitespaces in python that in the could I can specify how mach the space between the words

print "John and (5 spaces) Mark went to (3 spaces) London"

how could I specify 5 spaces as a code without typing it as " "


回答1:


You could try this:

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

Here you can find more information




回答2:


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

Am I understood corectly:

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



回答3:


If you want the numbers of spaces in the template string instead of the arguments to format:

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


来源:https://stackoverflow.com/questions/24414959/specifying-spaces-between-words

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!