【问题标题】:Specifying spaces between words指定单词之间的空格
【发布时间】:2023-03-09 16:12:01
【问题描述】:

我如何在 python 中使用空格,我可以指定单词之间的空格是多少

打印“约翰和(5 个空格)马克去了(3 个空格)伦敦”

如果不输入" ",我怎么能指定 5 个空格作为代码呢

【问题讨论】:

  • 线条从何而来?

标签: python tabs


【解决方案1】:

你可以试试这个:

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

Here you can find more information

【讨论】:

  • 还有什么可以使用例如 \s{5} 吗?
  • @user3771924 这是正则表达式语法,而不是 Python
【解决方案2】:
is there anyway to use for example \s{5} ?

我理解正确吗:

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

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-08
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      相关资源
      最近更新 更多