之间有什么区别
print(a, end=' ')
和
print(a, ' ')
在Python中?
答案 0 :(得分:3)
end
是print
函数的仅关键字参数,它声明将在print语句的末尾添加什么值。默认情况下,这是"\n"
(换行符)。
传递多个值进行打印,使用str.join
将关键字 - sep
参数(默认为' '
)作为分隔符连接在一起,所以......
print(a, ' ') # prints the value of str(a) ' '.join'ed with a space
# then terminated with a newline
"a \n"
print(a, ' ', sep="SEPARATOR") # produces...
"aSEPARATOR \n"
print(a, end=' ') # prints the value of a, terminated with a space
"a "