January 2019
Beginner
318 pages
8h 23m
English
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'
Read now
Unlock full access