Python内置函数(50)——print
英文文档:
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
Print objects to the text stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.
All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.
The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. Since printed arguments are converted to text strings, print() cannot be used with binary mode file objects. For these, use file.write(...) instead.
Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.
说明:
1. 用于对象打印输出。通过命名参数sep来确定多个输出对象的分隔符(默认' '),通过命名参数end确定输出结果的结尾(默认'\n'),通过命名参数file确定往哪里输出(默认sys.stdout),通过命名参数fiush确定输出是否使用缓存(默认False)。
>>> print(,,) >>> print(,,,sep = '+')
++
>>> print(,,,sep = '+',end = '=?')
++=?
2. sep、end、file、flush都必须以命名参数方式传参,否则将被当做需要输出的对象了。
>>> print(,,,'+','=?')
+ =?
3. sep和end参数必须是字符串;或者为None,为None时意味着将使用其默认值。
>>> print(1,2,3,sep = 97,end = 100)
Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
print(1,2,3,sep = 97,end = 100)
TypeError: sep must be None or a string, not int
>>> print(1,2,3,sep = None,end = None)
1 2 3
4. 不给print传递任何参数,将只输出end参数的默认值。
>>> print() >>> print(end = 'by 2016')
by 2016
5. file参数必须是一个含有write(string) 方法的对象。
>>> class A:
@staticmethod
def write(s):
print(s) >>> a = A()
>>> print(1,2,3,sep = '+',end = '=?',file = a)
1
+
2
+
3
=?
Python内置函数(50)——print的更多相关文章
- python内置函数之print()
定义:将值打印到一个流对象,或者默认打印到sys.stdout. 语法: print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=Fal ...
- Python内置函数(57)——print
英文文档: print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) Print objects to the text str ...
- Python内置函数(50)——issubclass
英文文档: issubclass(class, classinfo) Return true if class is a subclass (direct, indirect or virtual) ...
- python内置函数print输出到文件,实现日志记录的功能
# bulid time 2018-6-22 import os import time def log(*args, **kwargs): # *kargs 为了通用 可不传 rule = &quo ...
- lambda 表达式+python内置函数
#函数 def f1(a,b): retrun a+b #lambda方式,形参(a,b):返回值(a+b) f2=lambda a,b : a+b 在一些比较简单的过程计算就可以用lambda p ...
- Python学习:6.python内置函数
Python内置函数 python内置函数,是随着python解释器运行而创建的函数,不需要重新定义,可以直接调用,那python的内置函数有哪些呢,接下来我们就了解一下python的内置函数,这些内 ...
- Python | 内置函数(BIF)
Python内置函数 | V3.9.1 | 共计155个 还没学完, 还没记录完, 不知道自己能不能坚持记录下去 1.ArithmeticError 2.AssertionError 3.Attrib ...
- python内置函数
python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...
- python 内置函数和函数装饰器
python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...
随机推荐
- ubuntu安装时系统分区设置
1. 创建主分区:主分区,用于存放系统 20G 主分区 空间起始位置 Ext4日志文件系统 / 2. 创建swap分区:逻辑分区.大小设置为电脑内存大小,2G: 2048MB ...
- Min_25 筛 学习笔记
原文链接https://www.cnblogs.com/zhouzhendong/p/Min-25.html 前置技能 埃氏筛法 整除分块(这里有提到) 本文概要 1. 问题模型 2. Min_25 ...
- DS博客作业01—日期抽象数据类型设计与实现
1.本章学习总结 1.1 思维导图 1.2学习体会 开学就来了个大作业,还要求用的是c++语法,作为一个只听过没学过的未知语法,靠着CSDN和寝室大佬的帮助下渐渐地了解了一些c++的使用,现在也可以使 ...
- java去除查询实体字段多值之间空格
String str = 需要去除的字段; str.replaceAll(",","");
- Weblogic记录
有些坑还是要去踩,上来就docker一脸懵逼. 1.应用 https://www.cnblogs.com/xdp-gacl/p/4140683.html (1)安装 环境: 64位server2016 ...
- Shell脚本学习 - 流程控制和函数
继续Shell的学习.上两篇是关于基本数据类型,基本语法以及运算符相关,这一篇是流程控制相关(if, for, while) 流程控制 if else 流程控制不可为空,如果else没有语句执行,就不 ...
- Redis数据库概述
Redis数据库概述 Redis是什么 redis是一个高性能的key-value存储系统.支持的value类型相对更多,包括string,list,set,zset(sorted set --有序集 ...
- linux磁盘满了的处理
1.查看磁盘使用情况 cd / df -h 如果 总量Size和Used一样,按就证明磁盘满了 2.查看当前文件下每个文件大小 du -sh * 一层一层去查,就可以查到占用空间最大的那个文件及产生 ...
- socket error:10053
系统提示:10053,由于超时或其它失败,连接中止 服务端和客户端并没有出现连接错误或主动关闭连接 发生这个错误的原因往往是连接上了,但是长时间没有通信,所以连接被挂起了 防止的办法就是自己设计心跳包 ...
- VB.NET或C#报错:You must hava a license to use this ActiveX control.
VB.NET或者C# winform开发时,如果使用了Microsoft Visual Basic 6.0 ActiveX,并动态创建该控件实例,那么程序移植到没有安装Visual Basic 6.0 ...