print( )函数调用——pytnon小练

print()函数
一、print
1、打印字符串、表达式值

print(1)
print('mypython')
print(1+2)

在这里插入图片描述

2、不进行换行输出

print('hello','world','python')

在这里插入图片描述

二、print与文件结合
新建文档并写入

1、首先写入的盘符要存在
2、使用file=fp格式
3、a+表示文件如果不存在就创建,存在就在文件内容的后面继续增加
fp=open('D:/text.txt','a+')
print('hello world',file=fp)
fp.close()

在这里插入图片描述
若提示permission undenied
则管理员权限打开软件再次运行

猜你喜欢

转载自blog.csdn.net/m0_51336041/article/details/118671631