切片:[:]
一个很有意思的概念,从某位置到某位置
比如 0~2,3~4,4~6
注意,如果是从开始的位置开始可以省略,所以我们会看到[:2]
同理,如果是结束到最后的位置,也可以省略[3:]
1 2 3 4 5 6 7 8 9 10 11 12 |
>>> pystr = 'Python' >>> pystr[0] 'P' >>> pystr[-1] 'n' >>> pystr[2:5] 'tho' >>> pystr[:2] 'Py' >>> pystr[3:] 'hon' >>> |
另外:
pystr[2:7]并不会报错,只是返回的结果和pystr[2:6]相同
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021