【问题标题】:remove white space in front of comma or apostrophe - Python删除逗号或撇号前面的空格 - Python
【发布时间】:2020-11-03 12:59:52
【问题描述】:

如何删除撇号或逗号前面的空格,以便 print() 中的句子读起来更好?

CTyear = 2020
Name1 = "Dave"
print("Hello",Name1,",","its the year",CTyear,".")

“你好,戴夫,现在是 2020 年。”

【问题讨论】:

    标签: python string removing-whitespace


    【解决方案1】:

    使用字符串格式:

    CTyear = 2020
    Name1 = "Dave"
    print(f"Hello {Name1}, it's the year {CTyear}.")
    

    输出

    Hello Dave, it's the year 2020.
    

    【讨论】:

      猜你喜欢
      • 2019-01-28
      • 1970-01-01
      • 1970-01-01
      • 2021-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      相关资源
      最近更新 更多