Python转义字符

Python转义字符:当需要在字符串中使用特殊字符时,使用 \ 转义字符。

注:转义字符在字符串中,注释也是字符串类型。

'''
\(在行尾时):续行符
\\  :反斜杠符号
\'  :单引号
\"  :双引号
\a  :响铃
\b  :退格(Backspace)
\000:空
\n  :换行
\v  :纵向制表符
\t  :横向制表符
\r  :回车
'''

输出 \000

# # \000
# print('\000')
# #  

其余转换字符:

# 续行符
strs = "hello " \
       "world."
print(strs)
# hello world.

# 在字符串中输出反斜杠
strs = '\\'
print(strs)
# \

# 在字符串中输出单引号
strs = '\''
print(strs)
# '

# 在字符串中输出双引号
strs = '\"'
print(strs)
# "

# 当存在 \b 时,进行输出
strs = 'abc\bd'
print(strs)
# abd

strs = 'abc\b\bd'
print(strs)
# ad


# 当存在 \n 时,进行输出
strs = 'a \nb'
print(strs)

# /v 相当于几个回车

# 当存在 \t 时,进行输出
strs = 'a \t b'
print(strs)
# a      b

# 当存在 \r 时,只输出最后一个 \r 后面的数据
strs = 'a \r b \r c'
print(strs)
#  c

# 当存在 \f 时,进行输出
strs = 'a \f b'
print(strs)
# a  b 换页

2020-02-08