all Python 3stringterm
string.ascii_lowercase
letters
The string 'abcdefghijklmnopqrstuvwxyz'. string.ascii_uppercase is 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
Syntax
string.ascii_lowercase # 'abcdefghijklmnopqrstuvwxyz'
string.ascii_uppercase # 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
It is an ordinary string, so string.ascii_lowercase.index(ch) gives a letter's alphabet position — the same as ord(ch) - ord('a') but without the magic number, which is the usual trick in Caesar-cipher exercises. Watch out that in on a string tests for a substring, not a single character: 'abc' is True while 'ac' is False even though both letters are in the alphabet.
Examples
import string
print(string.ascii_lowercase) # → abcdefghijklmnopqrstuvwxyz
print(string.ascii_uppercase) # → ABCDEFGHIJKLMNOPQRSTUVWXYZ
print(len(string.ascii_lowercase)) # → 26
lower_only = [c for c in 'Hello' if c in string.ascii_lowercase] # → ['e','l','l','o']
upper_only = [c for c in 'Hello' if c in string.ascii_uppercase] # → ['H']
See also
Open in the full glossarydocs.python.orgReport an inaccuracy