Lecture 1: Python output function print()& escape character


1. The output function print()

# csdn : XCsss98
# 时间  : 2021/2/19 19:43
#输出数字
print(2333)
#输出字符串
print('XCsss98')
#含有运算符的表达式
print(9+8+3)
#输出到文件中
fp=open('D:/text.txt','a+')
print('把文档输出到D盘的text.txt文件中,没这个文件则a+自动创建',file=fp)
fp.close()
#不换行输出,输出内容在一行
print('XC','sss','98')

2. Escaping characters

#转义字符
print('hellow\nworld') #\n换行
print('hellow\tworld') #\t空格
print('hellow\rworld') #\r回车,World覆盖前面的
print('hellow\bworld') #\b退一格

print('http:\\\www.baidu.com')
print('老实说:\'大家好\'')
print(r'hello\nword')#原字符,不希望字符串中的转义字符起作用,结尾不能是\,可以是\\

Insert picture description here

Guess you like

Origin blog.csdn.net/buxiangquaa/article/details/113870630