输出函数print

秒速五厘米 2024-03-17 23:51 235阅读 0赞

print(“hello world”)

# 可以输出数字
print(1111)
print(2222)

# 可以输出字符串
print(‘helloworld’)
print(“helloworld”)

# 可以输出运算符的表达式
print(5+6)

# 将数据输出文件中,注意点:1.所指定的盘符存在,2.使用file=fp
fp=open(‘D:/text.txt’,’a+’)
# a+中的a是指以读写的方式打开文件,+是指如果文件不存在,则创建文件;如果文件存在则在原有的文件内容上追加(追加的意思是指,如果存在txt,且txt文件中已有helloworld,则再追加一行helloworld)
print(‘helloworld’,file=fp)
fp.close()

# 不进行换行输出(输出内容在一行当中)
print(‘hello’,’world’,’python’)

8d0a08ee9aa4470990e3c7fb2f9a739e.png

8cc615fd7fcc4579a73a94a06943afe8.png

发表评论

表情:
评论列表 (有 0 条评论,235人围观)

还没有评论,来说两句吧...

相关阅读