Python3 print()函数sep,end,file参数用法练习
来自builtins.py:
def print(self, *args, sep=' ', end='\n', file=None): # known special case of 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.
"""
pass 使用1,练习sep的用法:
print("file\n","abc","bcd","fff\n","poi")
print("-------------")
print("file\n","abc","bcd","fff\n","poi",sep='')
print("-------------")
print("file\n","abc","bcd","fff\n","poi",sep=' ')
print("-------------")
其结果为:
file
abc bcd fff
poi
-------------
file
abcbcdfff
poi
-------------
file
abc bcd fff
poi
-------------
使用2,练习end的用法:
print("file\n","abc","fff",sep='#########\n',end='')
print("--------------------")
print("file\n","abc","fff",sep='#########\n',end='\n')
print("--------------------")
print("file\n","abc","fff",sep='#########\n')
print("--------------------")
其结果为:
file
#########
abc#########
fff--------------------
file
#########
abc#########
fff
--------------------
file
#########
abc#########
fff
--------------------
使用3,练习file的用法:
with open('abc.txt','w') as f:
print("file\n","abc","fff",sep='#########\n',end='',file=f)
其结果:
将输出写到了文件abc.txt。
abc.txt的内容如下:
file
#########
abc#########
fff
注意文件末行没有换行符
Python3 print()函数sep,end,file参数用法练习的更多相关文章
- Python3 join函数和os.path.join用法
Python3 join函数和os.path.join用法 os.path.join()连接两个文件名地址的时候,就比os.path.join("D:\","test. ...
- python3: print()函数:def,end关键字介绍
print()函数是最最普通常见的函数,我们常用的方式为类似这种的没有任何设置的“ print("今天是个好日子") ” 的简单输出. 其实print()函数中含有如下几个关键字, ...
- [Python3] 019 函数:确认过参数,返回对的值
目录 0. 函数简介 1. 初识函数 2. 函数的参数与返回值 少废话,上例子 3. 查找函数的帮助文档 4. 函数的参数 (1) 参数分类 (2) 结构介绍 1) 普通参数 2) 默认参数 3) 关 ...
- python3 print函数的用法
1. 输出字符串 >>> strHello = 'Hello World' >>> print (strHello) Hello World 2. 格式化输出整数 ...
- python3 print() 函数带颜色输出 示例
1.1 实现过程: 终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关. 转义序列是以ESC开头,即用\033来完成(ESC的ASCII码用十进制表示是27,用八进制表示就 ...
- (转)Python标准库:内置函数print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
原文:https://blog.csdn.net/caimouse/article/details/44133241 https://www.cnblogs.com/owasp/p/5372476.h ...
- Python中print()函数的用法详情
描述 print() 方法用于打印输出,最python中常见的一个函数. 在交互环境中输入help(print)指令,可以显示print()函数的使用方法. >>> help(pri ...
- print()函数的end 参数
print()函数含end参数时:结束的时候已什么结尾,后面的参数可以是任何形式 [print() 默认以'\n' 结尾] 输出结果: print()函数不含end参数时: 输出结果:
- python 中的 print 函数与 list函数
print() 函数: 传入单个参数时默认回车换行,关键词 end 可以用来避免输出后的回车(换行), 或者以一个不同的字符串结束输出. >>> a, b = 0, 1 >& ...
随机推荐
- jQuery框架-3.jQuery自定义封装插件和第三方插件
一.jQuery的封装扩展 1.jQuery中extend方法使用 (挂在到jQuery和jQuery.fn两对象身上的使用) 1.1.官方文档定义: jQuery.extend Merge th ...
- Alpha冲刺 - (6/10)
Part.1 开篇 队名:彳艮彳亍团队 组长博客:戳我进入 作业博客:班级博客本次作业的链接 Part.2 成员汇报 组员1(组长)柯奇豪 过去两天完成了哪些任务 基于ssm框架的前后端交互测试,结合 ...
- Python + selenium + unittest装饰器 @classmethod
前言 前面讲到unittest里面setUp可以在每次执行用例前执行,这样有效的减少了代码量,但是有个弊端,比如打开浏览器操作,每次执行用例时候都会重新打开,这样就会浪费很多时间. 于是就想是不是可以 ...
- Could not load file or assembly 'System.Data.SQLite ... 试图加载格式不正确的程序
坑爹的System.Data.SQLite. 先给出下载地址:http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki ...
- Android-FileUtils-工具类
FileUtils-工具类 是对文件操作处理的方法进行了封装,提供了公共的方法: package common.library.utils; import android.annotation.Sup ...
- java学习笔记—校验码的实现(15)
校验码的出现主要的任务是解决表单的重复提交问题. public void doGet(HttpServletRequest request, HttpServletResponse response) ...
- clickonce联机模式
发布时选择该程序只能联机使用,这样本地就不会进行安装. 参考地址:https://blog.csdn.net/dqs78833488/article/details/52513948
- jquery input 实时监听输入
$('input').bind('input propertychange', function() { alert('hello world') });
- jenkins详解(一)
还是以以下几个问题来学习这个软件: 1.jenkins是什么? 2.为什么要用jenkins? 3.怎么用jenkins? 1.jenkins是什么? Jenkins是一个开源的.提供友好操作界面的持 ...
- C语言多线程编程一
1. Windows下同时打开多个对话框: #include <Windows.h> #include <process.h> //创建线程 void runmsg(void ...