我正在使用 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
换行符