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

高洛峰
Release: 2017-01-09 11:38:40
Original
1262 people have browsed it

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

name='G'
b=name.lower()
Copy after login

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

4. split: Split the string into sequences

'1+2+3+4+5'.split('+')
Copy after login

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()
Copy after login

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!


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!