码迷,mamicode.com
首页 > 编程语言 > 详细

Python字符串图解

时间:2018-08-12 17:36:42      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:python   cte   word   rac   pos   cond   har   字符   osi   

>>> 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字符串图解

标签:python   cte   word   rac   pos   cond   har   字符   osi   

原文地址:https://www.cnblogs.com/frisk/p/9463237.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!