网站首页 > 技术文章 正文
Python3中的输出语句:
函数原型如下:
print(help(print)) 使用此语句打印
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.分隔符:
a = 'hello'
b = 'Python'
c = 'ixusy88'
# 默认空格
print('1----',a,b,c)
# 指定分割符
print('2----',a,b,c,sep='!')
print('3----',a,b,c,sep=',')
"""
输出结果:
1---- hello Python ixusy88
2----!hello!Python!ixusy88
3----,hello,Python,ixusy88
"""
end:
a = 'hello'
b = 'Python'
c = 'ixusy88'
# end 默认是新的一行,即下一个打印会在新的一行输出
print('1----',a,b,c)
# 指定结束符,
print('2----',a,b,c,end='###')
print('3----',a,b,c)
print('4----',a,b,c)
"""
结果:
1---- hello Python ixusy88
2---- hello Python ixusy88###3---- hello Python ixusy88
4---- hello Python ixusy88
"""输出流:
a = 'hello'
b = 'Python'
c = 'ixusy88'
# file ,默认是sys.stdout
print('1----',a,b,c)
# file,指定输出流,输出到文件中
print('2----',a,b,c,file=open('test.txt','w'))
print('-1--')
# 读取文件,并打印出来
print(open('test.txt').read() )
print('-2--')
# 也可以修改sys.stdout,把定向到一个文件,之后的所有输出都会保存到文件中;
import sys
print('sys.stdout之后')
sys.stdout = open('test_2.txt','w')
print('1----',a,b,c)
print(sys.platform)
"""
输出结果:
1---- hello Python ixusy88
-1--
2---- hello Python ixusy88
-2--
sys.stdout之后
"""输出文件中的内容
猜你喜欢
- 2024-10-01 利用神经网络模型检测摄像头上的可疑行为
- 2024-10-01 使用神经网络的自动化特征工程(神经网络的特点及使用场景)
- 2024-10-01 Python基础学习必备的8个最常用的内置函数
- 2024-10-01 利用Click和argparse给你Python程序构建一个优雅的命令行界面
- 2024-10-01 langchain中的LLM模型使用介绍(llvm 分析)
- 2024-10-01 学习Python内置函数(range)来打印数学乘法表
- 2024-10-01 Python 100天 15:print("hello world")茴香豆的写法
- 2024-10-01 python3入门实例一:Hello World(python的hello world程序编写)
- 2024-10-01 python基础篇:讲讲python的内置函数一
- 2024-10-01 (39)python少儿编程之内建函数(python常用内建函数)
- 最近发表
-
- 聊一下 gRPC 的 C++ 异步编程_grpc 异步流模式
- [原创首发]安全日志管理中心实战(3)——开源NIDS之suricata部署
- 超详细手把手搭建在ubuntu系统的FFmpeg环境
- Nginx运维之路(Docker多段构建新版本并增加第三方模
- 92.1K小星星,一款开源免费的远程桌面,让你告别付费远程控制!
- Go 人脸识别教程_piwigo人脸识别
- 安卓手机安装Termux——搭建移动服务器
- ubuntu 安装开发环境(c/c++ 15)_ubuntu安装c++编译器
- Rust开发环境搭建指南:从安装到镜像配置的零坑实践
- Windows系统安装VirtualBox构造本地Linux开发环境
- 标签列表
-
- cmd/c (90)
- c++中::是什么意思 (84)
- 标签用于 (71)
- 主键只能有一个吗 (77)
- c#console.writeline不显示 (95)
- pythoncase语句 (88)
- es6includes (74)
- sqlset (76)
- apt-getinstall-y (100)
- node_modules怎么生成 (87)
- chromepost (71)
- flexdirection (73)
- c++int转char (80)
- mysqlany_value (79)
- static函数和普通函数 (84)
- el-date-picker开始日期早于结束日期 (76)
- js判断是否是json字符串 (75)
- c语言min函数头文件 (77)
- asynccallback (87)
- localstorage.removeitem (77)
- vector线程安全吗 (73)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- 无效的列索引 (74)
