Python string processing functions-Python tutorial

Source: Internet
Author: User
This article mainly introduces a concise summary of Python string processing functions. This article summarizes some common string processing functions. For more information, see Returns the string with the specified characters removed.

Blank characters are removed by default.

Delete the first and last characters: str. strip ([char])
Delete the first character: str. lstrip ([char])
Delete str. strip ([char])

Determine whether to match the first and last characters

True is returned if the matching is successful. otherwise, False is returned.
Match the first character: str. startswith (char [, start [, end])
Match the last character: str. endswith (char [, start [, end])

Search for characters and find the position of the returned characters; otherwise,-1 is returned.

Search for str. find (char [, start [, end]) starting with a string.
Search for str. find (char [, start [, end]) from the end of the string.

Break down characters

Str. split ([sep [, maxsplit])

Connection character

Str. join (iterable)
"Str" is the connection character, and "iterable" is the connected iteratable string

Replacement Character

Str. replace (old, new [, count])
Returns the replaced string, which is the number of times the count mark is replaced. by default, all characters are replaced.

Breaks down strings by line breaks and returns the row list

Str. splitlines ([keepends])
Line breaks are not retained unless keepends is True.

Case-sensitive conversion

Case-insensitive: str. swapace ()
Convert to uppercase: str. upper ()
To lowercase: str. lower ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.