SLICING AND SPLICING STRINGS
Python enables you to extract substrings of a string (called “slicing”) using array notation. Slice notation is start:stop:step, where the start, stop, and step values are integers that specify the start value, end value, and the increment value. The interesting part about slicing in Python is that you can use the value -1, which operates from the right-side instead of the left-side of a string.
Some examples of slicing a string are here:
text1 = "this is a string"
print('First 7 characters:',text1[0:7])
print('Characters 2-4:',text1[2:4])
print('Right-most character:',text1[-1])
print('Right-most 2 characters:',text1[-3:-1])
The output from the preceding code block is here:
First 7 characters: this is Characters 2-4: is Right-most character: g Right-most 2 characters: in
Later in this appendix you will see how to insert a string in the middle of another string.
Testing for Digits and Alphabetic...