Python中常用的输出函数print()
2021/12/26 12:37:02
本文主要是介绍Python中常用的输出函数print(),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Python中常用的输出函数print()
print()函数可以输出那些内容
1.数字
例:
print(10) #10 print(5.21) #5.21
2.字符串
例:
print('hello python') # hello python print("hello python") # hello python
注意: 字符串要加单,双引号,不加的话计算机不识别
3.含有运算符的表达式的结果
例:
print(3+2) #5 print(5-1) #4
print()函数可以将内容输出的地目的
1.显示器
例:
print(10) # 10 print('hello world') # hello world
2.文件:将数据输出在文件中
注意: 1.所制定的盘符存在
2.使用 file=fp(如果是a,那就是file=fp,不加 file=fp 结果会是新建成功,但没有内容
例:
fp=open('D:/text.txt','a+') # a+是以读写的方式打开文件,文件不存在就创建文件,存在就是在文件内容后面继续追加 print('helloworld',file=fp) fp.close() # D盘中创建test.txt 里面内容为 helloworld print('hello','world','python') #不进行换行输出(输出内容在一行当中)helloworld
小白学python的学习笔记,后续持续更新,敬请关注!共同学习进步!点赞是我更新的动力,哈哈~~
下期见伙计们!
这篇关于Python中常用的输出函数print()的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python