Python Glossary Русский

all Python 3stringterm

string.ascii_letters

letters

The string of every ASCII letter, lower-case and upper-case (a-z + A-Z). Handy for generating passwords and for validation.

Syntax

string.ascii_letters  # 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

This constant is ASCII and nothing else: Cyrillic, umlauts and other Unicode letters never appear in it, whatever the locale, so testing membership here is stricter than c.isalpha(), which happily accepts 'ё' or 'é'. For real passwords or tokens reach for the secrets module rather than random, whose output is reproducible from the generator state and is meant for simulation, not security.

Examples

import string
print(string.ascii_letters)  # → abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
print(len(string.ascii_letters))  # → 52
import string
import random
pwd = ''.join(random.choices(string.ascii_letters, k=8))  # → случайный пароль 8 символов
all_alpha = [c for c in 'Hello1' if c in string.ascii_letters]  # → ['H','e','l','l','o']
print('a' in string.ascii_letters)  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy