gpt4 book ai didi

python - 动态打印一行

转载 作者:IT老高 更新时间:2023-10-28 12:09:21 34 4
gpt4 key购买 nike

我想做几条语句,它们提供标准输出,而语句之间没有换行符。

具体来说,假设我有:

for item in range(1,100):
print item

结果是:

1
2
3
4
.
.
.

如何让它看起来像:

1 2 3 4 5 ...

更好的是,是否可以在最后一个数字上打印单个数字,这样屏幕上一次只有一个数字?

最佳答案

打印项改为:

  • 打印项目, 在 Python 2.7 中
  • print(item, end="") 在 Python 3 中

如果要动态打印数据,请使用以下语法:

  • print(item, sep=' ', end='', flush=True) 在 Python 3 中

关于python - 动态打印一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3249524/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com