在python中打印没有换行的语句?
我想知道是否有一种方法可以打印没有换行符的元素,例如
x=['.','.','.','.','.','.']
for i in x:
print i
并且将打印........
而不是通常打印的内容
.
.
.
.
.
.
.
.
谢谢!
-
这可以用轻松完成打印() 函数 与
Python 3中 。for i in x: print(i, end="") # substitute the null-string in place of newline
会给你
......
在 Python v2中, 您可以通过以下方式使用该
print()
函数:from __future__ import print_function
作为源文件中的 第一条 语句。
Old: print x, # Trailing comma suppresses newline New: print(x, end=" ") # Appends a space instead of a newline
请注意,这类似于我最近回答的问题(https://stackoverflow.com/a/12102758/1209279),其中包含一些有关此
print()
功能的其他信息(如果您感到好奇)。