官术网_书友最值得收藏!

String slicing

Strings support slicing, which means getting characters by a specified range from your string. Let's take a look at the following example. Note that starting index value is always included and an end value is always excluded.

Consider a string, str = "Programming":

>>> str[0:2]
'Pr'
>>> str[2:5]
'ogr'

Now, the default of an omitted first index is zero, as in the example:

>>> str[:2] + str[2:]
'Python'
>>> str[:4] + str[4:]
'Python'
>>> str[:2]
'Py'
>>> str[4:]
'on'
>>> str[-2:]
'on'
主站蜘蛛池模板: 怀来县| 驻马店市| 深州市| 商南县| 黔南| 洱源县| 新津县| 花垣县| 朝阳县| 北宁市| 明光市| 海安县| 河北省| 榕江县| 桂东县| 商南县| 镶黄旗| 吉隆县| 屏南县| 乌苏市| 古田县| 马尔康县| 永安市| 海口市| 准格尔旗| 田东县| 任丘市| 方城县| 仁寿县| 峨边| 富蕴县| 建平县| 武邑县| 遵化市| 清流县| 乐安县| 铁岭市| 竹北市| 大名县| 平泉县| 平安县|