Python标准库:内置函数print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
2023-09-14 09:10:34 时间
本函数是实现对象以字符串表示的方式格式化输出到流文件对象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 深圳
相关文章
- python标准库学习6
- Python标准库:内置函数all(iterable)
- Python标准库:内置函数compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)
- Python标准库:内置函数complex([real[, imag]])
- Python标准库:内置函数delattr(object, name)
- Python标准库:内置函数dict(**kwarg)
- Python标准库:内置函数bytes([source[, encoding[, errors]]])
- Python标准库:内置函数iter(object[, sentinel])
- Python标准库:内置函数len(s)
- Python标准库:内置函数int(x=0)
- Python标准库:内置函数repr(object)
- Python标准库:内置函数__import__(name, globals=None, locals=None, fromlist=(), level=0)
- python coding style guide 的快速落地实践——业内python 编码风格就pep8和谷歌可以认作标准