The string module in Python

The string module of Python helps us to quickly access some useful string constants.

ConstantsDescription
string.ascii_lowercase
Contains the lowercase letters 'abcdefghijklmnopqrstuvwxyz'
string.ascii_uppercase
Contains the uppercase letters 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
string.ascii_letters
The combination of the ascii_lowercase and ascii_uppercase constants.
string.digits
Contains the string '0123456789'.
string.hexdigits
Contains the string '0123456789abcdefABCDEF'.
string.octdigits
Contains the string '01234567'.
string.punctuation
Contains the string of ASCII characters '!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~'.
string.whitespace
The string of all ASCII characters which are whitespace. This includes characters whitespace, linefeed, formfeed, tab, return, and vertical tab.
string.printable
The string combination of ASCII characters which are printable. This includes digits, ascii_letters, punctuation, and whitespace.

Example:

print(string.ascii_lowercase)
print(string.ascii_uppercase)
print(string.ascii_letters)
print(string.digits)
print(string.hexdigits)
print(string.octdigits)
print(string.punctuation)
print(string.whitespace)
print(string.printable)

The output of this is as follows:

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




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