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 >& ...
随机推荐
- PHP性能分析工具:xhprof
phpize的安装 一直想装VLD却一直没装上,因为需要用到phpize,但这个工具大部分机子都没有装,上网搜了一下大部分都是讲phpize的应用没有讲怎么安装. 今天终于搜到了,不过是要在li ...
- idea jvm 优化
修改对应配置文件 64位的是idea64.exe.vmoptions -Xms2048m -Xmx2048m -Xmn1024m -XX:PermSize=512m -XX:MaxPermSize=5 ...
- [label][git-commands] Several Git Commands
The process of Git commands Operation 1. git commit -m 'fist post' Windows PowerShellCopyright (C) 2 ...
- [label][Node.js] Three content management systems base on Node.js
1. Keystonejs http://keystonejs.com/ 2. Apostrophe http://apostrophenow.org/
- ERROR Function not available to this responsibility.Change responsibilities or contact your System Administrator.
APPLIES TO: Navigation: Help > Diagnostics > Custom Code > Personalize or Help > Diag ...
- devexpress停靠菜单
dxDockSite1.Width := 27; dxDockPanel1.DockTo(dxDockSite1, dtLeft, 0); dxDockPanel2.DockTo(dxDockPane ...
- [LeetCode 题解]: Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...
- CentOS 7 IPv6关闭
你可以用两个方法做到这个.方法 1编辑文件/etc/sysctl.conf,vi /etc/sysctl.conf添加下面的行:net.ipv6.conf.all.disable_ipv6 =1net ...
- EAS.Net 在程序里配置组件
public class BeforStart { /// <summary> /// 程序配置初始化 /// </summary> public static void EA ...
- Tempdb--临时对象缓存
SQL Server删除一个临时对象时,不移除该对象的条目,当再次使用时,就无须重新创建临时对象,SQL Server为临时对象缓存一个数据页和一个IAM页,并回收剩余页,如果临时表的大小超过8MB, ...