Substrings
A substring is a selected area from within a string. We can access parts of a string using square brackets and 1 or 2 parameters separated by a colon.
Substring method |
What it does |
string[:x] |
Starts at character in position 0 and goes up to the position before x |
string[:-x] |
Starts at character in position 0 and goes until there are x characters left |
string[x:] |
Starts at position x and goes to the end of the string |
string[-x:] |
Starts x characters before the end of the string and goes to the end |
string[x:y] |
Starts at the character in position x and goes up to the position before y |
Example substrings