Home  >  Article  >  Backend Development  >  How to remove letters from python string

How to remove letters from python string

silencement
silencementOriginal
2019-06-27 14:15:2912498browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn