string — 常见字符串操作

源代码: Lib/string.py


字符串常量

此模块中定义的常量:

字符串。 ascii_letters

串联的 ascii_lowercase and ascii_uppercase 常量的描述见下文。此值不从属区域设置。

字符串。 ascii_lowercase

小写字母 'abcdefghijklmnopqrstuvwxyz' 。此值不从属区域设置且不会改变。

字符串。 ascii_uppercase

大写字母 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 。此值不从属区域设置且不会改变。

字符串。 digits

字符串 '0123456789' .

字符串。 hexdigits

字符串 '0123456789abcdefABCDEF' .

字符串。 octdigits

字符串 '01234567' .

字符串。 punctuation

被认为是标点符号的 ASCII 字符字符串,在 C 区域设置: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ .

字符串。 printable

被认为是可打印的 ASCII 字符字符串。 这是组合的 digits , ascii_letters , punctuation ,和 whitespace .

字符串。 whitespace

包含所有被视为空白的 ASCII 字符的字符串。这些字符包括空格、Tab 制表符、换行、回车、换页符及垂直制表符。

自定义字符串格式化

The built-in string class provides the ability to do complex variable substitutions and value formatting via the format() 方法描述在 PEP 3101 Formatter 类在 string module allows you to create and customize your own string formatting behaviors using the same implementation as the built-in format() 方法。

class 字符串。 Formatter

The Formatter 类具有下列公共方法:

format ( format_string , / , * args , ** kwargs )

The primary API method. It takes a format string and an arbitrary set of positional and keyword arguments. It is just a wrapper that calls vformat() .

3.7 版改变: A format string argument is now 仅位置 .