这里给出四种使用print()函数输出的方式:输出字符串、输出数字、输出表达式、输出内容到文件。
# 作 者: 要努力,努力,再努力
# 开发时间: 2022/4/5 11:02
# 1. 输出字符串
print('helloworld!')
# 这样输出是错误的:print(helloworld)
print("helloworld")
# 2. 输出数字
print(520)
print(98.5)
# 3. 输出含有运算符的表达式
# 3和1为操作数,加号为操作符
print(3 + 1)
# 4. 将数据可以输出到文件中
# a+ 打开文件方式 如果文件不存在就创建;存在就追加
# 首先要指定保存在哪个盘当中
# 其次要使用file=fp
fp = open('E:/test.txt', 'a+')
print('helloworld', file=fp)
fp.close()
# 不进行换行输出 输出内容在一行当中
print('hello', 'world', 'Python')
这里补充一下其他几种文件打开方式:
在一个python文件中直接复制上面的代码,你会得到以下运行结果:
helloworld!
helloworld
520
98.5
4
hello world Python
【Python 输出函数就是这些~如有不对之处,欢迎批评指正。】