python:水平打印而不是当前默认打印

标签 python

我想知道我们是否可以在 python 中按行打印。

基本上我有一个循环,它可能会运行一百万次,我正在该循环中打印出一些战略计数。所以如果我能像行一样打印,那将非常酷

print x
# currently gives
# 3
# 4
#.. and so on

我看起来像

print x
# 3 4

最佳答案

在 Python2 中:

data = [3, 4]
for x in data:
    print x,    # notice the comma at the end of the line

或者在 Python3 中:

for x in data:
    print(x, end=' ')

打印

3 4

关于python:水平打印而不是当前默认打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8437964/

相关文章:

python - 如何使用python获取此字符串

python - 根据最后一个 LARGEST 值替换数据框中当前值的最快方法

python - Python 3 : How/when to call it? 中的 PyEval_InitThreads(传奇继续令人作呕)

Python get 引发 HTTPError 400 Client Error,但手动访问 URL 后,get 暂时有效

python - 将大文件逐行读入 Python2.7 时的内存使用

java - 寻求用于套接字编程(Java 或 Python)的高级库

python - 根据权重为 networkx 边着色

python - 勾选 Python 中的 Python 实例

python - 无法从网页中选择正确的 div

python - 如何在python中使用selenium查找html类中是否存在元素