Python的输出print()函数
1.输出在控制台上
#可以输出数字
print(520)
print(19.5)
#可以输出字符串
print('hellowold')
print("helloworld")
#可以输出含有运算符的表达式
print(3+1)
print(2*5)
运行结果图
2.输出在文件中
# 将数据输出在文件中 注意点:1.所指定的盘符存在 2.使用file=
fp = open('C:/py/text.txt', 'a+')#a+如果文件不存在就创建,存在就在文件内容的后面继续追加
print('helloworld', file=fp)
fp.close()
我是输出保存在C盘的py文件下
打开text.txt文件,就会输出helloworld
3.在一行输出
#不进行换行输出(输出内容在一行当中)
print('hello','huang','banana')
运行结果图