end = in print()调用的含义

时间:2018-02-03 19:27:21

标签: python python-3.x

之间有什么区别
print(a, end='  ')

print(a, '  ')
在Python中

1 个答案:

答案 0 :(得分:3)

endprint函数的仅关键字参数,它声明将在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 "
相关问题