Python字符串图解
Posted 撒欢
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python字符串图解相关的知识,希望对你有一定的参考价值。
>>> word = "Python"
>>> 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‘
>>> word[:2] # 从开始到2位置
‘Py‘
>>> word[4:] # 从4到末尾
‘on‘
>>> word[-2:] # 从-2到末尾
‘on‘
| P | y | t | h | o | n |
0 1 2 3 4 5 6
-6 -5 -4 -3 -2 -1
以上是关于Python字符串图解的主要内容,如果未能解决你的问题,请参考以下文章