Python's string
module provides constants for string related operations. To use them, import the string
module:
>>> import string
string.ascii_letters
:Concatenation of ascii_lowercase
and ascii_uppercase
:
>>> string.ascii_letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
string.ascii_lowercase
:Contains all lower case ASCII characters:
>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
string.ascii_uppercase
:Contains all upper case ASCII characters:
>>> string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
string.digits
:Contains all decimal digit characters:
>>> string.digits
'0123456789'
string.hexdigits
:Contains all hex digit characters:
>>> string.hexdigits
'0123456789abcdefABCDEF'
string.octaldigits
:Contains all octal digit characters:
>>> string.octaldigits
'01234567'
string.punctuation
:Contains all characters which are considered punctuation in the C
locale:
>>> string.punctuation
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
string.whitespace
:Contains all ASCII characters considered whitespace:
>>> string.whitespace
' \t\n\r\x0b\x0c'
In script mode, print(string.whitespace)
will print the actual characters, use str
to get the string returned above.
string.printable
:Contains all characters which are considered printable; a combination of string.digits
, string.ascii_letters
, string.punctuation
, and string.whitespace
.
>>> string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'