差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
blog:python:string [2022/09/12 09:07] – [ord & chr] caodan | blog:python:string [2023/05/19 20:21] (当前版本) – [字符串截取操作] caodan | ||
---|---|---|---|
行 1: | 行 1: | ||
# 字符串 | # 字符串 | ||
+ | 用单引号`'' | ||
+ | |||
+ | 如果字符串中既包含`' | ||
+ | |||
+ | 例如: `str=" | ||
## 字符串截取操作 | ## 字符串截取操作 | ||
行 16: | 行 21: | ||
| `str[4:] ` | efg | characters from position 4 to the end | | | `str[4:] ` | efg | characters from position 4 to the end | | ||
| `str[-2:] ` | fg | characters from the second last to the end | | | `str[-2:] ` | fg | characters from the second last to the end | | ||
- | | `str[-1:] ` | fg | the last character | + | | `str[-1:] ` | f |
| `str[: | | `str[: | ||
| `str[::-1]` | gfedcba | | `str[::-1]` | gfedcba |