Home>Article>Backend Development> A brief analysis of how to use Python's built-in string processing functions

A brief analysis of how to use Python's built-in string processing functions

高洛峰
高洛峰 Original
2017-01-09 11:38:40 1145browse

1. lower(): Convert all uppercase letters to lowercase letters. For example:

name='G' b=name.lower()

2. title"": Convert the string into a title, that is, the first letter of all words is capitalized and other letters are lowercase. The usage method is the same as lower()

3. replace: Returns the string obtained after all matching items of a certain string are replaced.

'This is a test'.replace('is','are')

4. split: Split the string into sequences

'1+2+3+4+5'.split('+')

The default program uses all spaces as separators.

5. strip: Returns a string with spaces on both sides (excluding internal) removed

' in wh is kepy '.strip()

6. translate: replaces some parts of the string. The translate knowledge handles individual characters. But multiple replacements can be performed at the same time. Multiple replacements mean that a can be replaced with b and c with d at the same time, while replace can only replace a with b at a time. The usage of translate is relatively complicated. If you need to use it, please read the document specifically introducing it.

For more articles on how to use Python’s built-in string processing functions, please pay attention to 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