Home > Article > Backend Development > How to remove letters from python string
To remove the letters in a string, you can use the index method of the string.
For example, we create a string named s
s = 'python'
If we want to take out the letter t, we can
s[2]
The output result is
't'
Remember that the index subscript of a string starts from 0, which means that the index corresponding to the letter p is 0. The string also supports negative indexes
s[-1]
and the output is
'n'
also You can intercept the specified index
s[2:4]
and output it as
'th'
The above is the detailed content of How to remove letters from python string. For more information, please follow other related articles on the PHP Chinese website!