How to Create a List of Alphabets in Python?

Estimated read time 2 min read

In Python, you can create a list of alphabets by using the string module, which provides a constant string of ASCII characters, including the lowercase and uppercase alphabets. Here’s an example:

import string

# Create a list of lowercase alphabets
lowercase_alphabets = list(string.ascii_lowercase)
print(lowercase_alphabets)

# Create a list of uppercase alphabets
uppercase_alphabets = list(string.ascii_uppercase)
print(uppercase_alphabets)

In this example, we first import the string module. We then use the ascii_lowercase constant provided by the string module to create a string of lowercase alphabets and convert it to a list using the list() function. We assign this list to the variable lowercase_alphabets. We then print this list using the print() function.

We then create a list of uppercase alphabets in the same way, using the ascii_uppercase constant provided by the string module. We assign this list to the variable uppercase_alphabets and print it using the print() function.

The output of this program would be:

['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

These are the lists of lowercase and uppercase alphabets, respectively.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply