Next / Previous / Contents / TCC Help System / NM Tech homepage

28.2. string: Utility functions for strings

Variables and functions for working with character strings.

ascii_letters

A string containing all the letters from ascii_uppercase and ascii_lowercase.

ascii_lowercase

The characters that are considered lowercase letters in the ASCII character set, namely:

"abcdefghijklmnopqrstuvwxyz"
ascii_uppercase
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"

The value of this constant does not depend on the locale setting; see Section 19.4, “What is the locale?”.

digits

The decimal digits: "0123456789".

hexdigits

The hexadecimal digits: "0123456789abcdefABCDEF".

letters

A string containing all the characters that are considered letters in the current locale.

lowercase

A string containing all the characters that are considered lowercase letters in the current locale.

maketrans(s, t)

Builds a translation table to be used as the first argument to the .translate() string method. The arguments s and t are two strings of the same length; the result is a translation table that will convert each character of s to the corresponding character of t.

>>> import string
>>> bingo=string.maketrans("lLrR", "rRlL")
>>> "Cornwall Llanfair".translate(bingo)
'Colnwarr Rranfail'
>>> "Cornwall Llanfair".translate(bingo, 'ai')
'Colnwrr Rrnfl'

octdigits

The octal digits: "01234567".

printable

A string containing all the printable characters.

punctuation

All printable characters that are not letters or digits in the current locale. If ASCII is the locale's current encoding, these characters are included:

!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

uppercase

A string containing all the characters that are considered uppercase letters in the current locale. May not be the same as ascii_uppercase

whitespace

A string containing all the characters considered to be white space in the current locale. For ASCII this will be:

"\t\n\x0b\x0c\r "

See Section 9.2, “Definition of “whitespace””.