字符转义

基本类型 / 字符串

# \t 插入制表符。
# \b 插入退格符。
# \n 插入换行符。
# \r 插入回车符。
# \' 或 ' 插入单引号。
# \" 插入双引号。
# \\ 插入反斜杠字符。

escaped = "She said \"Hello!\" to me."
# escaped is 'She said "Hello!" to me.'

# 换用另一种引号:无需转义
other_quotes = 'She said "Hello!" to me.'
apostrophe = "It's fine"

# 按十六进制码、Unicode 码和名称
letters = ("\x41", "\u0041", "\N{LATIN CAPITAL LETTER A}")
# letters is ('A', 'A', 'A')

# 原始字符串:"\" 保持原样
path = r"C:\Temp\new"
# repr 会把每个 "\" 加倍:'C:\\Temp\\new'

print(f"{escaped = }")
print(f"{other_quotes = }")
print(f"{apostrophe = }")
print(f"{letters = }")
print(f"{path = }")
print(path)