问题
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