# 转义字符
# \n newline换行,光标移动到下一行开头
print('hello\nworld')
>>
hello
world
# \r return回车,光标移动到本行开头
print('hello\rworld')
>>
world
# \t tab制表符,光标移动到下一组4个空格的开始处
print('hello\tworld')
print('helloooo\tworld')
>>
hello world
helloooo world
# \b backspace回退一个字符
print('hello\bworld')
>>
hellworld
# 字符串中有特殊用途的字符\\ \' \"
print('http:\\\\www.baidu.com')
print('大家好,我叫\'hello\'')
>>
http:\\www.baidu.com
大家好,我叫'hello'
# 原字符,不希望字符串中的转义字符起作用,就是用原字符,就是在字符串之前加上r或R,最后一个字符不能为反斜杠
print(r'hello\nworld')
>>
hello\nworld
2.转义字符与原字符
于 2023-07-06 16:50:00 首次发布