blog:python:string

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
blog:python:string [2022/09/12 09:07] – [ord & chr] caodanblog:python:string [2023/05/19 20:21] (当前版本) – [字符串截取操作] caodan
行 1: 行 1:
 # 字符串 # 字符串
  
 +用单引号`''` 或者 `""` 括起来的任意字符表示字符串
 +
 +如果字符串中既包含`'` 也包含 `"`, 可以用转义字符来表示。
 +
 +例如: `str="I'm \"tux\""`
 ## 字符串截取操作 ## 字符串截取操作
  
行 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        | the last character                                            |
 | `str[:]`    | abcdefg  | all the characters                                            | | `str[:]`    | abcdefg  | all the characters                                            |
 | `str[::-1]` | gfedcba  | `[::-1]` 字符串最后一个字符到第一个字符,也就是对字符串逆序   | | `str[::-1]` | gfedcba  | `[::-1]` 字符串最后一个字符到第一个字符,也就是对字符串逆序   |
  • blog/python/string.1662944842.txt.gz
  • 最后更改: 2022/09/12 09:07
  • caodan