end: 默认是换行,表示两个字符串最后以什么结尾。eg: 换行 end="\n"
sep: 默认是空格,表示两个字符串之间用什么分割。eg: 空格 sep=" "
使用1,练习sep的用法:
print("file\n","abc","bcd","fff\n","poi")
print("-------------")
print("file\n","abc","bcd","fff\n","poi",sep='')
print("-------------")
print("file\n","abc","bcd","fff\n","poi",sep=' ')
print("-------------")
其结果为:
使用2,练习end的用法:
print("file\n","abc","fff",sep='#########\n',end='')
print("--------------------")
print("file\n","abc","fff",sep='#########\n',end='\n')
print("--------------------")
print("file\n","abc","fff",sep='#########\n')
print("--------------------")
其结果为:
使用3,练习file的用法:
with open('abc.txt','w') as f:
print("file\n","abc","fff",sep='#########\n',end='',file=f)
其结果:将输出写到了文件abc.txt。
abc.txt的内容如下:
注意:文件末行没有换行符