Python print函数参数详解
官方文档
print(…)
print(value, …, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
参数解析
value:需要输出的值,可以是多个,用”,”分隔。
sep:多个输出值之间的间隔,默认为一个空格。
end:输出语句结束以后附加的字符串,默认是换行(’\n’)。
file:输出的目标对象,可以是文件也可以是数据流,默认是“sys.stdout”。
flush:flush值为True或者False,默认为Flase,表示是否立刻将输出语句输出到目标对象。
演示
默认:print(value, …, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)
>>> print("hello world")
hello world
1
2
当value有多个:
>>> print("hello","world")
hello world
1
2
当sep为”,”
>>> print("hello","world",sep=",")
hello,world
1
2
当end为“”
>>>print("hello","world",end="")
>>>print("hello","world")
hello worldhello world
1
2
3
当file指向test.txt
test = open("test.txt", "w")
print("hello","world",sep="\n", file=test)
1
2
3
此时当前目录下会新建一个test.txt文件里面内容为
hello
world
1
2
flush=False
该参数只有两个选项True or False。
当flush=False时,输出值会存在缓存,然后在文件被关闭时写入。
当flush=True时,输出值强制写入文件。
原文:https://blog.csdn.net/weixin_41939225/article/details/79782793
Python print函数参数详解的更多相关文章
- Python函数参数详解
Python函数参数详解 形参与实参 什么是形参 在定义函数阶段定义的参数称之为形式参数,简称形参,相当于变量名. 什么是实参 在调用函数阶段传入的值称为实际参数,简称实参.相当于"变量值& ...
- PHP date函数参数详解
PHP date函数参数详解 作者: 字体:[增加 减小] 类型:转载 time()在PHP中是得到一个数字,这个数字表示从1970-01-01到现在共走了多少秒,很奇怪吧 不过这样方便计 ...
- Go语言Slice作为函数参数详解
Go语言Slice作为函数参数详解 前言 首先要明确Go语言中实质只有值传递,引用传递和指针传递是相对于参数类型来说. 个人认为上诉的结论不对,把引用类型看做对指针的封装,一般封装为结构体,结构体是值 ...
- Python3学习笔记(十一):函数参数详解
一.位置参数 根据参数的位置来传递参数,调用函数时,传递的参数顺序和个数必须和定义时完全一致 # 定义函数 def man(name, age): print("My name is %s, ...
- 【集成学习】sklearn中xgboot模块中fit函数参数详解(fit model for train data)
参数解释,后续补上. # -*- coding: utf-8 -*- """ ############################################## ...
- Python包管理工具setuptools之setup函数参数详解
**********************************************************对所学内容的简单汇总******************************** ...
- python datetime模块参数详解
Python提供了多个内置模块用于操作日期时间,像calendar,time,datetime.time模块,它提供 的接口与C标准库time.h基本一致.相比于time模块,datetime模块的接 ...
- python中可变长度参数详解
1. *args用法:python会将所有位置的参数收集到一个元组中 2. **args用法:python会将关键字参数传递给一个新的字典.**允许将关键字参数转换为字典 用法见如下代码: def f ...
- CGBitmapContextCreate函数参数详解
函数原型: CGContextRef CGBitmapContextCreate ( void *data, size_t width, size_t height, size_t bitsPerCo ...
随机推荐
- Qemu编译qemu-system-arm
/********************************************************************************* * Qemu编译qemu-syst ...
- Linux C single linked for any data type
/************************************************************************** * Linux C single linked ...
- 51Nod 1091:线段的重叠(贪心)
1091 线段的重叠 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 X轴上有N条线段,每条线段包括1个起点和终点.线段的重叠是这样来算的,[10 ...
- (8)propetry装饰器
propetry是一个内置函数,用来将一个功能伪装成一个数据属性 property将一个方法伪装成一个数据属性class People: def __init__(self,name,height,w ...
- CTF-练习平台-WEB之 计算题
四.计算题 打开连接 输入后发现只能输入一个数字,在火狐浏览器中按F12,打开查看器 ,如图所示修改最大长度 输入答案后验证,当当当~~flag出现
- m mm等和envsetup.sh
envsetup.sh简介: Android 完成编译的时候先执行 source build/envsetup.sh.在这个shell 脚本中定义了 help, croot, m, mm, mmm 等 ...
- STL版本号简单介绍
说明:本文仅供学习交流.转载请标明出处.欢迎转载! 本文的參考文献为:<STL源代码剖析>侯捷 (1)HP STL:全部STL的祖先版本号,由C++之父Alexander S ...
- npm bower gulp
npm即nodejs package manager ,是nodeJs的包管理工具,使用前需安装nodeJs(https://www.npmjs.com.cn/getting-started/inst ...
- Upgrade to or Install Cinnamon 2.4 in Ubuntu
http://www.omgubuntu.co.uk/2014/11/install-cinnamon-2-4-ubuntu-14-04-lts sudo add-apt-repository ppa ...
- 淘宝 code 使用
淘宝 code上 svn 使用,基本流程: 新建项目 mkdir 创建 branches 文件夹(新建项目的时候,只有 trunk) copy 来创建新分支 checkout 主干和(或)分支到本地 ...