前言
本文主要介绍python中的输入、输出与注释。
一、输出
1.print输出
#print number
print(12)
#print 字符
print("helloworld")
#print 运算表达式
print(3+2)
#不换行输出
print(2+3,'hello','world',65)
2.将数据输出于文件
fp=open('D:/document/教材/大四下/python学习/world.txt','a+')#文件不存在,创建文件,有文件,文件后写入东西
print('kello world',file=fp)
fp.close()
3.转义字符
#\n 换行;\r,回车;\t,水平制表符,注意制表位的占满与否;\b,退格。
print('hello\nworld')
print('hello\tw')
print('hellooo\tw')
print('hello\rworld')
print('hello\bworld')#退一个
#反斜杠\\,\'
print('hellohttp:\\www.com')
print('hellohttp:\\\\www.com')
print('老师说:\'大哥大\'')
#原字符:让转译字符无用,r
print(r'hellohttp:\\\\www.com')
#注意事项,最后一个字符不能是一个反斜线,两个反斜线
print('hellohttp:\\\\www.co\m')
二、输入与注释
1.input输入
#input()默认输入string类型变量
#input()其他类型输入与print类似
baba=input('爸爸的爸爸叫')
print(baba)
2.注释
#(这是单行注释)
'''
这
是
多
行
注
释
'''