python print的参数介绍
参考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.
在python中,print默认向屏幕输出指定的文字,例如:
>>>print('hello,world')hello worldprint的完整格式为
print(objects,sep,end,file,flush),其中后面4个为可选参数- sep
在输出字符串之间插入指定字符串,默认是空格,例如:>>>print("a","b","c",sep="**")a**b**c - end
在print输出语句的结尾加上指定字符串,默认是换行(\n),例如:>>>print("a",end="$")a$
print默认是换行,即输出语句后自动切换到下一行,对于python3来说,如果要实现输出不换行的功能,那么可以设置end=''(python2可以在print语句之后加“,”实现不换行的功能) - file
将文本输入到file-like对象中,可以是文件,数据流等等,默认是sys.stdout>>>f = open('abc.txt','w')>>>print('a',file=f) - flush
flush值为True或者False,默认为Flase,表示是否立刻将输出语句输入到参数file指向的对象中(默认是sys.stdout)例如:>>>f = open('abc.txt','w')>>>print('a',file=f)
可以看到abc.txt文件这时为空,只有执行f.close()之后才将内容写进文件。
如果改为:>>>print('a',file=f,flush=True)
则立刻就可以看到文件的内容
- sep
python print的参数介绍的更多相关文章
- python DRF获取参数介绍
DRF获取参数的方式 例如url url(r'^demo/(?P<word>.*)/$', DemoView.as_view()) 在类视图中获取参数 url:http://127.0.0 ...
- Python print函数参数详解
官方文档 print(…) print(value, …, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False) Prints the valu ...
- python 函数参数介绍
python 函数参数介绍 python 使用过程总,总会遇到 *args,**kw形式的参数,总是一头雾水,而且网上介绍的或是叫法不一,为此专门深入实践进而了解了函数参数的使用 具体请看代码 #-* ...
- python之定义参数模块argparse(二)高级使用 --传参为函数的实现
我们在文章python之定义参数模块argparse的基本使用中介绍了argparse模块的基本使用方法 当前传入的参数只能是int.str.float.comlex类型,不能为函数,这有点不方便,但 ...
- Linux下查看某个进程打开的文件数-losf工具常用参数介绍
Linux下查看某个进程打开的文件数-losf工具常用参数介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在linux操作系统中,一切皆文件.通过文件不仅仅可以访问常规数据,还 ...
- Python 基于python操纵redis入门介绍
基于python操纵redis入门介绍 by:授客 QQ:1033553122 测试环境 redis-3.0.7 CentOS 6.5-x86_64 python 3.3.2 基于Python操作R ...
- Python 模块EasyGui详细介绍
转载:无知小德 Python 模块EasyGui详细介绍 EasyGui 官网: http://easygui.sourceforge.net 官方的教学文档:http://easygui-docs- ...
- python获取命令行参数的方法(汇总)
介绍python获取命令行参数的方法:getopt模和argparse模块. python版本:2.7 一.getopt模块 主要用到了模块中的函数: options, args = getopt.g ...
- 一、Python 模块EasyGui详细介绍
Python 模块EasyGui详细介绍 EasyGui 官网: -http://easygui.sourceforge.net 官方的教学文档: -easygui-docs-0.96\tutoria ...
随机推荐
- php - 去除php代码中的多余空格
<?php class Test{ public function test(){ $tmplContent = file_get_contents('./test.php'); $tmplCo ...
- docker 学习(2)
docker容器中安装vim ubuntu 中默认未装vim,docker run ubuntu vim 出现: container_linux.go:247: starting container ...
- HDU - 1054 Strategic Game (二分图匹配模板题)
二分图匹配模板题 #include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdi ...
- 团体程序设计天梯赛-练习集 L2-001 紧急救援 (25 分)
作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上.当其他城市有紧急求 ...
- Tricky Sum
In this problem you are to calculate the sum of all integers from 1 to n, but you should take all po ...
- git 使用规范
git使用资料: https://github.com/peak-c/my-git 公司内部使用开发规范: 一. 代码库介绍 个人开发库(git@gitlab.adrd.sohuno.com:sper ...
- DiyCode开源项目 TopicActivity 分析
1.首先看看TopActivity效果. 2.TopicActivity是一个继承BaseActivity的.前面分析过BaseActivity了.主要有一个标题栏,有返回的图标. 3.贴一下T ...
- Redis实现之字符串
简单动态字符串 Redis中的字符串并不是传统的C语言字符串(即字符数组,以下简称C字符串),而是自己构建了一种简单动态字符串(simple dynamic string,SDS),并将SDS作为Re ...
- socketCluster 使用
<html> <head> <title>test</title> <script src="https://cdn.bootcss.c ...
- leetcode 【 Remove Element 】python 实现
题目: Given an array and a value, remove all instances of that value in place and return the new lengt ...