英文文档:

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的更多相关文章

  1. python内置函数之print()

    定义:将值打印到一个流对象,或者默认打印到sys.stdout. 语法: print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=Fal ...

  2. Python内置函数(57)——print

    英文文档: print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) Print objects to the text str ...

  3. Python内置函数(50)——issubclass

     英文文档: issubclass(class, classinfo) Return true if class is a subclass (direct, indirect or virtual) ...

  4. python内置函数print输出到文件,实现日志记录的功能

    # bulid time 2018-6-22 import os import time def log(*args, **kwargs): # *kargs 为了通用 可不传 rule = &quo ...

  5. lambda 表达式+python内置函数

    #函数 def f1(a,b): retrun  a+b #lambda方式,形参(a,b):返回值(a+b) f2=lambda a,b : a+b 在一些比较简单的过程计算就可以用lambda p ...

  6. Python学习:6.python内置函数

    Python内置函数 python内置函数,是随着python解释器运行而创建的函数,不需要重新定义,可以直接调用,那python的内置函数有哪些呢,接下来我们就了解一下python的内置函数,这些内 ...

  7. Python | 内置函数(BIF)

    Python内置函数 | V3.9.1 | 共计155个 还没学完, 还没记录完, 不知道自己能不能坚持记录下去 1.ArithmeticError 2.AssertionError 3.Attrib ...

  8. python内置函数

    python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...

  9. python 内置函数和函数装饰器

    python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...

随机推荐

  1. [linux]使用curl进行GET、POST和网页调试

    以前在win下开发的时候,习惯用的调试工具是谷歌自带控制台和postman,谷歌控制台比较方便,但不能对请求进行重发,post虽然很好用,但是感觉还是有点'大'.在linux下,其实完全没有那么麻烦, ...

  2. HangFire快速入门 分布式后端作业调度框架服务

    安装 NuGet 上有几个可用的Hangfire 的软件包.如果在ASP.NET应用程序中安装HangFire,并使用Sql Server作为存储器,那么请在Package Manager Conso ...

  3. 第二次作业-熟悉git

    GIT地址 https://github.com/gentlemanzq/yunsuanhomework GIT用户名  gentlemanzq 学号后五位  62320 博客地址 https://w ...

  4. Jmeter中主要管理器功用

    不管是在使用jmeter进行性能测试还是接口自动化测试时经常用到各种管理器进行对参数的处理,但是有时候分不清几种管理器的具体用法,所以做个笔记,列一下吧(所列内容基于版本为3.2) 主要内容包含以下: ...

  5. URL控制器

    自定义路由 from django.conf.urls import url from app01 import views urlpatterns = [ url(r'^books/$', view ...

  6. ABC113 AK失败记

    众所周知, ABC是一场水题盛宴, 也是一场AK盛宴. 但是我却没能AK. 原因也十分可笑: 我在一开始觉得题目太简单, 颓废了.直到我看了第4题之后才找到状态并A了此题...最后时间来不及第三题最后 ...

  7. PBRT笔记(12)——蒙特卡洛积分

    这里还涉及到pdf.方差等概念,推荐去看<全局光照技术:从离线到实时渲染> 积累分布函数 cumulative distribution function (CDF) 蒙特卡洛估算 为了计 ...

  8. Spring Cloud微服务笔记(五)Feign

    Feign 一.Feign概述 Feign是一个声明式的Web Service客户端.在Spring Cloud 中使用Feign,可以做到 使用HTTP请求访问远程服务,就像调用本地方法一样,同时它 ...

  9. 我的 FPGA 学习历程(01)—— FPGA 基础知识和 Quartus 的安装

    高级的嵌入式市场主要分为以下三类:ARM.DSP 和 FPGA. 其中 ARM 是行业内的佼佼者,目前几乎所有的安卓智能手机都使用 ARM 授权的 CPU架构:而 DSP(数字信号处理器) 早年就被大 ...

  10. Response输出excel设置文本样式

    在网上查了些Response导出excel然后设置样式的方法,发现没有一个可行的于是开始自己研究, 发现可以通过输出样式的方式进行配置,我要设置的是全文本格式在excel样式是这样的mso-numbe ...