Slicing¶
Indices and tables¶
Background¶
Slicing is an often used feature of Python sequences. This set of exercises will give you an opportunity to try out the various things you can do with them.
Exercise¶
Use the following string for the exercises in this section:
There once was a town named Blooth
- Get the first character of the string.
- Get the last character of the string
- Get every other character of the string, working from left-to-right.
- Get every other character of the string, working from right-to-left.
- Get the string in reverse
- Extract just the name of the town.
- Replace the word “town” with “city”
- Create a copy of the string and prove whether the copy results in a new object or not. Explain your result.
- Create a list from the string. Then, create a copy of that list and prove whether the copy results in a new object or not. Explain your result.