0
点赞
收藏
分享

微信扫一扫

【Python从零到壹】print的使用方法


Python中的print,是我们学习Python的第一个命令,它可以输出数字,字符串,运算符表达式,以及输出到文件。

以下是我们的测试,大家可以照着敲一下,知道输出数字或者字符串的格式就可以了:

#可以输出数字
print(401)
print(98.5)
#可以输出含有运算符的表达式
print(3+4)

#可以输出字符串
print(‘hello world’)
print(“hello world”)
#print(hello world) 这种形式是错误的

#将数据输出到文件中

fp=open(‘E:/muchen.txt’,‘a+’)
#a+表示有文件就追加,没文件就新建
print(‘hell world’,file=fp)
fp.close()

#不进行换行输出
print(“hello”,“world”,“python”)

【Python从零到壹】print的使用方法_Python


举报

相关推荐

0 条评论