Python中print()函数中的一些参数
print()函数可以实现打印——只是对程序员友好的标准输出流的接口。
源码:
def print(self, *args, sep=' ', end='\n', file=None):
1.sep=”str”
设置输出字符串之间的字符串,默认是空格。
a,b,c='abc' print(a,b,c,sep='..') #a..b..c
2.end=”str”
设置输出文本末尾的字符串。默认是”\n”
a,b,c='abc' print(a,b,c,end='.over.\n') #a b c.over.
3.file=””
指定文本将要发送到的文件、标准流或者其它类似文件的对象,默认是sys.stdout
a,b,c='abc'
print(a,b,c,sep=',',end='/over\n',file=open('print.txt','a'))
file=open('print.txt','a') 设置了输出文件路径,’a’设置了打开文件的方式是添加模式,所以字符串会加在文件末尾,不会重写文件。
//print.txt 运行几次后的文本内容 a,b,c/over a,b,c/over a,b,c/over a,b,c/over
浙公网安备 33010602011771号