List of Alphabets Python

Here we develop a program to print the list of alphabets in Python. An alphabet is a set of letters or symbols in a fixed order used to represent the basic set of speech sounds of a language, especially the set of letters from A to Z. We will develop a Python program to initialize the list with the English alphabets a-z using various methods.

Alphabet list Python

This python program using the For Loop to print the list of uppercase and lowercase alphabets. The most general method that comes to our mind is using the brute force method of running a loop till 26 and incrementing it while appending the letters in the list. The ord() method is used to find the Unicode value of a character passed as its argument. The chr() method returns a character (a string) from an integer (represents Unicode code point of the character).

# Python program to print list of alphabets

# initializing empty list
list_upper = []
list_lower = []

upper = 'A'
for c in range(0, 26):
   list_upper.append(upper)
   upper = chr(ord(upper) + 1)

lower = 'a'
for c in range(0, 26):
   list_lower.append(lower)
   lower = chr(ord(lower) + 1)

# print uppercase alphabets
print('Uppercase Alphabets: ', list_upper)
# print lowercase alphabets
print('Lowercase Alphabets: ', list_lower)

Output:-

Uppercase Alphabets: [‘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’]
Lowercase Alphabets: [‘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’]

Python Alphabet List

This method is similar to the above method, but rather a shorthand method. In this program, we use the list comprehension technique.

# Python program to print list of alphabets

# using list comprehension
list_upper = [chr(i) for i in range(ord('A'), ord('Z') + 1)]
list_lower = [chr(i) for i in range(ord('a'), ord('z') + 1)]

# print uppercase alphabets
print('Uppercase Alphabets: ', list_upper)
# print lowercase alphabets
print('Lowercase Alphabets: ', list_lower)

Output:-

Uppercase Alphabets: [‘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’]
Lowercase Alphabets: [‘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’]

Alphabet list in Python

The map() function applies a given function to each item of an iterable (list, tuple, etc.) and returns a list of the results. It typecasts the numbers in a range to a particular data type, char in this case, and assigns to the list.

# Python program to print list of alphabets

# using map()
list_upper = list(map(chr, range(65, 91)))
list_lower = list(map(chr, range(97, 123)))

# print uppercase alphabets
print('Uppercase Alphabets: ', list_upper)
# print lowercase alphabets
print('Lowercase Alphabets: ', list_lower)

Output:-

Uppercase Alphabets: [‘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’]
Lowercase Alphabets: [‘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’]

This python program also performs the same task but in a different way. In this program, we are using the built-in function to print the list of alphabets. The string.ascii_uppercase method returns all uppercase alphabets and string.ascii_lowercase method returns all lowercase alphabets.

# Python program to print list of alphabets

import string  #importing string function

# using string
list_upper = list(string.ascii_uppercase)
list_lower = list(string.ascii_lowercase)

# print uppercase alphabets
print('Uppercase Alphabets: ', list_upper)
# print lowercase alphabets
print('Lowercase Alphabets: ', list_lower)

Output:-

Uppercase Alphabets: [‘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’]
Lowercase Alphabets: [‘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’]

Order List Alphabetically

In the previous program, we used string.ascii_uppercase and string.ascii_lowercase but in this program, we are using string.ascii_letters method. This method returns all lowercase and uppercase alphabets as a single string.

# Python program to print list of alphabets

import string  #importing string function

# using string
list_alpha = list(string.ascii_letters)

# print alphabets
print('Alphabets: ', list_alpha)

Output:-

Alphabets: [‘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’]

Also See:- Check if String Starts with Vowel

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *