【问题标题】:How to print output in Single line [duplicate]如何以单行打印输出[重复]
【发布时间】:2020-02-27 12:48:38
【问题描述】:

我想知道如何在一行中打印输出

我想打印成:1234

而不是

1
2
3
4

代码:

 # n = (get in from user)
 i=1
 while (i<=n):
     print (i,)
     i +=1

【问题讨论】:

  • print(i, end='') 在 Python3 中
  • 你应该使用 print(i,end = ' ')
  • 如果您使用的是 Python 3,为什么要标记您的问题 python-2.7
  • @khelwood 可能是他未来的导入?
  • @norok2 可能是。无论哪种方式,它都应该在问题中说。

标签: python python-2.7


【解决方案1】:

这可能会有所帮助:

对于 Python 3

print(i,end='')

对于 Python 2

print(i),

【讨论】:

  • OP 要求 Python 2,而不是 Python 3。
猜你喜欢
  • 1970-01-01
  • 2012-08-15
  • 2013-10-01
  • 2016-04-20
  • 1970-01-01
  • 2021-12-21
  • 2020-10-23
  • 2015-11-01
  • 2018-08-10
相关资源
最近更新 更多