To get a part of a Python string, you can use the bracket notation:
letters = 'abcdefg'
print(letters[0:3])
Where the notation is [from:to].
The result of the above code is:
abc
The numbers are indexes into the string. The result string contains the character at the from index, but does not contain the character at the to index.
Here's another example:
letters = 'abcdefg'
print(letters[2:5])
the result is:
cde
Leave a comment