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 >& ...
随机推荐
- msfconsole邮件收集器模块
msfconsole search email collector use auxiliary/gather/search_email_collector show options 下面我们设置域名. ...
- ScreenCapture手动卸载教程-Xproer.ScreenCapture
此教程包含WindowsXP,Windows7(x86) ,Windows7(x64),Firefox,Chrome卸载教程. 1.1. 手动卸载控件-Windows XP 主要步骤如下: 1.关闭所 ...
- Frames of Reference参考框架
Frames of Reference参考框架 When describing the position and orientation of something (for example, your ...
- 終于解決调用wordpress 4.3 xmlrpc api 发布包含分类的文章时返回“抱歉,文章类型不支持您的分类法”错误的問題
這個問題我找了很多資料都沒有明說是如何解決,后來突發奇想得出我的解決方案如下,所以特此記錄一下: object postId = blogService.NewPost(0,"admin&q ...
- hdu 4281 Judges' response(多旅行商&DP)
Judges' response Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- [Delphi]编译条件
当软件在多个DELPHI版本下编译时,需要处理各版本的不同情况,使用编译条件技术实现. 万一博客,编译指令基础使用介绍:http://www.cnblogs.com/del/category/1686 ...
- SQL Server触发器的基本使用
sqlserver_SQL触发器的使用及语法(转自:百度文库) 定义: 何为触发器?在SQL Server里面也就是对某一个表的一定的操作,触发某种条件,从而执行的一段程序.触发器是一个特殊的存储过程 ...
- Elasticsearch 安装的时候,Unsupported major.minor version 51.0问题的解决
Elasticsearch安装的时候报错 bootstrap/Elasticsearch : Unsupported major.minor version 51.0 网上一般说的方法是,升级或者降级 ...
- Sqler-Monitor
针对Sqler Monitor 功能做了整理 ##SqlServices ## Cluster. Alwayson Single ##Replicaion ##: 1:undelivedcmds mo ...
- C#学习(2):委托
1.疑问: 1.委托是什么? 2.为什么需要委托? 3.委托能用来做什么? 4.如何自定义委托? 5..NET默认的委托类型有哪几种? 6.怎样使用委托? 7.多播委托是什么? 8什么是泛型委托? 9 ...