Python中转意符
时间: 2024-04-16 13:22:39 浏览: 20
Python中的转义字符用于表示一些特殊字符,例如换行符、制表符等。下面是一些常见的转义字符及其用法[^2]:
1. \n:表示换行符。
```python
print('hello\nworld') # 输出:
# hello
# world
```
2. \t:表示制表符。
```python
print('hello\tworld') # 输出:hello world
```
3. \\:表示反斜杠。
```python
print('hello\\world') # 输出:hello\world
```
4. \r:表示回车符。
```python
print('hello\rworld') # 输出:world
```
5. \': 表示单引号。
```python
print('\'hello\'') # 输出:'hello'
```
6. \": 表示双引号。
```python
print('\"hello\"') # 输出:"hello"
```
7. \a:表示响铃符。
```python
print('hello\a') # 输出:hello(会发出响铃声)
```
8. \b:表示退格符。
```python
print('hello\bworld') # 输出:hellworld
```
9. \f:表示换页符。
```python
print('hello\fworld') # 输出:
# hello
# world
```
10. \v:表示垂直制表符。
```python
print('hello\vworld') # 输出:
# hello
# world
```
11. \0:表示空字符。
```python
print('hello\0world') # 输出:hello world
```