How to remove letters from python string

silencement
Release: 2019-07-08 10:28:16
Original
12521 people have browsed it

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'
Copy after login

If we want to take out the letter t, we can

s[2]
Copy after login

The output result is

't'
Copy after login

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]
Copy after login

and the output is

'n'
Copy after login

also You can intercept the specified index

s[2:4]
Copy after login

and output it as

'th'
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template