Python中的输出函数:print()函数
print()函数可以输出数字、字符串以及含有运算符的表达式
print(520)
print(98.5)
print('hello')
print("hello")
print(1+2)
将数据输出到文件中;注意点:1.所指定的盘符存在 2.使用file=fp
fp=open('D:/text.txt','a+')
'''第一个为文件路径
a+是以读写的方式打开文件,
文件若不存在则会新建一个,存在就在文件内容的后面继续追加'''
print('helloworld',file=fp)
fp.close()
进行不换行输出(输出内容在一行当中)
print('hello','world','Python')
Python中的转义字符:
\n 表示换行
\t 横向跳到下一制表位,一个制表位为4格
\r 将光标位置回退到本行的开头位置
\b 退一个格
\\ 会将前一个\消掉
\' 将 ' 从字符串的边界转换成为字符串的内容 "同理
原字符,不希望字符串中的转义字符起作用,就使用原字符,就是在字符串之前加上r,或R
注意事项:最后一个字符不能是反斜杠(可以是双杠)
print('hello\nworld')
'''hello
world'''
print('hello\tworld')
print('helloooo\tworld')
'''hello world'''
'''helloooo world'''
print('hello\rworld')
'''world'''
print('hello\bworld')
'''hellworld'''
print('http:\\\\www.baidu.com')
'''http:\\www.baidu.com'''
print('老师说:\'大家好\'')
'''老师说:'大家好'
print(r'hello\nworld')
'''hello\nworld'''