常用的转义字符
1.无法直接表示的字符
# python入门学习
# by SongCanCan
print('hello\nworld!')
print('hello\tworld')
print('hello\rworld')
print('hello\bworld')
运行结果:
2.在字符串中有特殊用途的字符
print('http:\\\\www.baidu.com')
print('小明说:\'你好\'')
运行结果:
原字符
当不希望字符串中的原字符起作用时就使用原字符,就是在字符串之前加上r或R。
print(r'hello\n world')
print(R'hello\n python')
运行结果: