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

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'
主站蜘蛛池模板: 潼南县| 西丰县| 谢通门县| 依安县| 九台市| 寿阳县| 河间市| 嘉义县| 红桥区| 刚察县| 和政县| 潮安县| 商水县| 高邮市| 龙胜| 正宁县| 石阡县| 车险| 蓬莱市| 双柏县| 宜兴市| 延边| 扶风县| 天全县| 和龙市| 黄浦区| 万全县| 迁安市| 罗山县| 鄂伦春自治旗| 建阳市| 六安市| 长丰县| 获嘉县| 榆林市| 彰化市| 法库县| 东兰县| 姚安县| 阳新县| 松溪县|