Python标准库:内置函数print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
2015-03-08 15:19
417 查看
本函数是实现对象以字符串表示的方式格式化输出到流文件对象file里。其中所有非关键字参数都按str()方式进行转换为字符串输出,关键字参数sep是实现分隔符,比如多个参数输出时想要输出中间的分隔字符;关键字参数end是输出结束时的字符,默认是换行符\n;关键字参数file是定义流输出的文件,可以是标准的系统输出sys.stdout,也可以重定义为别的文件;参数flush是立即把内容输出到流文件,不作缓存。
例子:
#print()
print(1, 2, 3, sep = ',', end = '\r\n')
print(1, 2, 3, sep = ' ', end = '\r\n')
with open(r'c:\\abc1.txt', 'w') as demo:
print(1, 2, 3, 88888888888, sep = ',', end = '\n', file = demo)
结果输出如下:
1,2,3
1 2 3
文件abc1.txt里:
1,2,3,88888888888
蔡军生 QQ: 9073204 深圳
例子:
#print()
print(1, 2, 3, sep = ',', end = '\r\n')
print(1, 2, 3, sep = ' ', end = '\r\n')
with open(r'c:\\abc1.txt', 'w') as demo:
print(1, 2, 3, 88888888888, sep = ',', end = '\n', file = demo)
结果输出如下:
1,2,3
1 2 3
文件abc1.txt里:
1,2,3,88888888888
蔡军生 QQ: 9073204 深圳
相关文章推荐
- Python标准库:内置函数print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
- Python 内建函数 - print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
- python3 中print函数参数详解,print(*values, sep=' ', end='\n', file=sys.stdout, flush=False)中参数介绍
- 解决ST3 for python 输入关键字print()带出参数print(value, ..., sep, end, file, flush)的解决方法
- Python3 print()函数sep,end,file参数用法练习
- Python标准库:内置函数input([prompt])
- Python标准库:内置函数set([iterable])
- [Python]print vs sys.stdout.write
- python的sys.stdout.flush()
- Python基础--人们一些最爱的标准库(sys os fileinput)
- traceback.print_stack(file=sys.stdout)找程序流程
- Python标准库:内置函数set([iterable])
- Python 2.7 学习笔记 内置语句、函数、标准库
- Python基础--人们一些最爱的标准库(sys os fileinput)
- Python标准库:内置函数set([iterable])
- [Python标准库]operator——内置操作符的函数接口
- [Python]print vs sys.stdout.write
- Python标准库:内置函数input([prompt])
- traceback.print_stack(file=sys.stdout)与traceback.extract_stack()
- 学习python 之 内置的函数