Alphabet range in Python

In Python, you can use the string module's ascii_lowercase and ascii_uppercase constants to get the range of lowercase and uppercase letters in the ASCII character set respectively. Here is an example code snippet:

import string

lowercase_alphabet = string.ascii_lowercase
print(lowercase_alphabet)

uppercase_alphabet = string.ascii_uppercase
print(uppercase_alphabet)

This will output:

abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Watch a course Python - The Practical Guide

You can also use the string.ascii_letters which will contain both the uppercase and lowercase letters.

import string

alphabet = string.ascii_letters
print(alphabet)

This will output:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ