Python字符串的截取原理,下标的位置图示
发布时间:2020-12-20 10:37:03 所属栏目:Python 来源:网络整理
导读:Python字符串截取时总是有些糊涂,从官网上找到一个图示,理解Python字符串是如何标记,的具体含义图示如下: ? +---+---+---+---+---+---+ | P | y | t | h | o | n | +---+---+---+---+---+---+ 0 1 2 3 4 5 6-6 -5 -4 -3 -2 -1 ? word[:2] # character fr
Python字符串截取时总是有些糊涂,从官网上找到一个图示,理解Python字符串是如何标记,的具体含义图示如下: ? +---+---+---+---+---+---+
| P | y | t | h | o | n |
+---+---+---+---+---+---+
0 1 2 3 4 5 6
-6 -5 -4 -3 -2 -1
? >>> word[:2] # character from the beginning to position 2 (excluded) ‘Py‘ >>> word[4:] # characters from position 4 (included) to the end ‘on‘ >>> word[-2:] # characters from the second-last (included) to the end ‘on‘ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python搭建服务器实现两个Android客户端间收发消息
- python – “__main__”只是一个字符串文字吗?
- python 变得更快功能实例
- 使用gitpython获取更改的文件
- 浅谈Python中函数的参数传递
- 使用Python和Flask流式传输数据会引发RuntimeError:在请求
- python – messenger平台中的位置小部件在移动版本中显示搜
- python – Pickle dump Pandas DataFrame
- Python json库中load、loads、dump、dumps的区别与用法
- Python – 我可以在不编写getter / setter的情况下包装属性