小编pe9*_*298的帖子

禁止在 python 3 str.format 中打印换行符

我正在使用 Python 3 并尝试将我的打印语句与 str.format 一起使用。

例如:

print ('{0:3d} {1:6d} {2:10s} '.format (count1,count2,string1)) 
Run Code Online (Sandbox Code Playgroud)

当我尝试使用 end=''来抑制后续的换行符时,这被忽略了。换行总是发生。

如何抑制后续的换行符?

来源:

int1= 1
int2 = 999
string1 = 'qwerty'
print ( '{0:3d} {1:6d} {2:10s} '.format (int1,int2,string1))
print ('newline')
print ( '{0:3d} {1:6d} {2:10s} '.format (int1,int2,string1,end=''))
print ('newline')
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "copyright", "credits" or "license()" for more information.
Run Code Online (Sandbox Code Playgroud)

1 999 qwerty
换行符

1 999 qwerty
换行符

python printing format newline python-3.x

4
推荐指数
1
解决办法
5020
查看次数

标签 统计

format ×1

newline ×1

printing ×1

python ×1

python-3.x ×1