python:print函数中end、sep参数的作用解释
print函数的功能是帮我们打印值以及变量到输出设备上,默认输出设备为屏幕
而print函数中的end、sep参数可以控制打印内容的格式
end参数
end参数用来设定print输出的内容以什么内容结尾,默认以 \n
换行结尾
print("hello")
print("world")
print("hello", end="") # 这里把结尾内容设置为了无
print("world")
运行结果
hello
world
helloworld # 这里的结尾处没有以任何元素分隔
sep参数
sep参数用来设定print中的参数在输出时用什么来连接,默认使用空格
来分隔
print("hello", "world")
print("hello", "world", sep="-") # 这里把输出使用 - 进行连接
运行结果
hello world
hello-world # 这里的是用 - 连接的