Python 简明教程

Python - String Methods

Python 的内置 str 类定义了不同的方法。它们有助于处理字符串。由于字符串是不可变对象,因此这些方法返回原始字符串的副本,在此副本上执行各自的处理。字符串方法可以分为以下几个类别 −

Python’s built-in str class defines different methods. They help in manipulating strings. Since string is an immutable object, these methods return a copy of the original string, performing the respective processing on it. The string methods can be classified in following categories −

Case Conversion Methods

在 Python 的 str 类的内建函数方法中,处理字符串对象中字符的转换。这个类别中有以下的一些方法:

This category of built-in methods of Python’s str class deal with the conversion of alphabet characters in the string object. Following methods fall in this category −

Alignment Methods

str 中的 following 方法控制字符串对象中字符的对齐。

Following methods in the str class control the alignment of characters within the string object.

Split and Join Methods

Python 有一些方法执行拆分和连接操作:

Python has the following methods to perform split and join operations −

Boolean String Methods

str 类中的 following 方法返回 True 或 False。

Following methods in str class return True or False.

Find and Replace Methods

以下是 Python 中的查找和替换方法:

Following are the Find and Replace methods in Python −

Translation Methods

以下列出的转换方法属于字符串:

Following are the Translation methods of the string −