【问题标题】:Python print mystery - How to print without a space [duplicate]Python打印之谜-如何在没有空格的情况下打印[重复]
【发布时间】:2016-01-24 07:48:54
【问题描述】:

如何在 Python 2.7 中拥有与以下相同的功能。请不要有未来。

print(item, end="")

【问题讨论】:

    标签: python python-2.7 python-3.x


    【解决方案1】:

    这对你有用吗?

    import sys
    sys.stdout.write(item)
    

    【讨论】:

      【解决方案2】:

      在美妙的end=(和sep=)出现在Python 3之前,我曾经在字符串中建立行并一键打印出字符串:

      str = "Three integers:"
      for iii in range (3):
          str = "%s %d" % (str, iii)
      print s
      

      不用说,我不再使用 Python 2 编写代码了 :-)

      【讨论】:

        猜你喜欢
        • 2012-04-16
        • 2010-10-04
        相关资源
        最近更新 更多