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 ...
随机推荐
- magento -- 如何在magento中进行产品的批量上传
花费了好多时间,阅读了magento官方论坛上几乎所有的批量上传产品的相关帖子,分析了大量相关magento代码,终于可以完全实现指产品批量上传的功能,免除网速慢,在页面之间跳来跳去,以及重复输入数据 ...
- shell 脚本实战笔记(7)--集群网络相关知识和环境搭建
前言: 对网络相关的知识, 做下笔记. 包括IP地址A/B/C的分类, 静态地址的配置/DNS配置, 以及网卡相关信息查看. *) A/B/C/D类网络地址的划分 IP地址=网络地址+主机地址 或 I ...
- 【linux基础】生成目录下所有图片的路径
command ls *.jpg > list.txt result .png .png .png .png .png command ls /home/xxx/input/*.png > ...
- poj-1015(状态转移的方向(01背包)和结果的输出)
#include <iostream> #include <algorithm> #include <cstring> #include <vector> ...
- test20190324 树
题意 树(tree.cpp/c/pas) [题目背景] 这道题标算在评测机上的时间约为自己电脑的2/3 [问题描述] [输入格式] 共 n+2 行.第 1 行 1 个数,n. 后面 2-n 行,每行两 ...
- Monocular 集成harbor helm 仓库
harbor 已经支持了helm 仓库(使用chartmuseum),Monocular 是一个不错的helm 仓库可视化工具 测试Monocular集成harbor 私服功能 使用docker- ...
- 前端基础之HTML快速入门
什么是 HTML? HTML 是用来描述网页的一种语言. HTML 指的是超文本标记语言 (Hyper Text Markup Language) HTML 不是一种编程语言,而是一种标记语言 (ma ...
- greasemonkey修改网页url
// ==UserScript== // @name JSHE_ModifyFunction // @namespace jshe // @include http://localhost/* // ...
- django model 插入数据方法
需要插入的数据表结构如下: class UserInfo(models.Model): user_id =models.AutoField(primary_key=True) user_name=mo ...
- vs2010开发环境恢复--(mysql,数据文件可直接拷贝,并可用navicat直接管理)
一.linq to mysql (DBLINQ) 1.安装mysql phpstudy2014,数据库文件可直接拷贝,在命令行中运行select version();查看版本为5.5.38 ,单独安装 ...