【发布时间】:2023-03-09 16:12:01
【问题描述】:
我如何在 python 中使用空格,我可以指定单词之间的空格是多少
打印“约翰和(5 个空格)马克去了(3 个空格)伦敦”
如果不输入" ",我怎么能指定 5 个空格作为代码呢
【问题讨论】:
-
线条从何而来?
我如何在 python 中使用空格,我可以指定单词之间的空格是多少
打印“约翰和(5 个空格)马克去了(3 个空格)伦敦”
如果不输入" ",我怎么能指定 5 个空格作为代码呢
【问题讨论】:
你可以试试这个:
space = " "
print "John and{}Mark went to{}London".format(space*5,space*3)
【讨论】:
is there anyway to use for example \s{5} ?
我理解正确吗:
space = " "
print "John and %s Mark went to %s London" % (space*5,space*3)
【讨论】:
如果您想要模板字符串中的空格数而不是 format 的参数:
>>> "John and{0:5s}Mark went to{0:3s}London".format("")
'John and Mark went to London'
【讨论】: