Print Alphabets in Python

Here we develop a program to print 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 print both uppercase alphabets and lowercase alphabets using ASCII values. We will also use the python built-in function to print alphabets.

Python Program to Print Alphabets from a to z

This python program using the For Loop to print uppercase and lowercase alphabets. We will take a user-defined function to print uppercase alphabets and lowercase alphabets using ASCII values. The chr() method returns a character (a string) from an integer (represents Unicode code point of the character). Then, calling the function and the result will be displayed on the screen.

ASCII value of uppercase alphabets – 65 to 90.
ASCII value of lowercase alphabets – 97 to 122.

# Python program to print alphabets

# function to print uppercase alphabets
def upperAlpha():
    for c in range(65, 91):
        print(chr(c), end = ' ')
    print('')

# function to print lowercase alphabets
def lowerAlpha():
    for c in range(97, 123):
        print(chr(c), end = ' ')
    print('')

# print uppercase alphabets
print('Uppercase Alphabets:')
upperAlpha()

# print lowercase alphabets
print('Lowercase Alphabets:',)
lowerAlpha()

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 alphabets. The string.ascii_uppercase method returns all uppercase alphabets and string.ascii_lowercase method returns all lowercase alphabets. The program is simply running a for loop over the string characters and printing them.

# Python program to print alphabets

import string  #importing string function

# function to print uppercase alphabets
def upperAlpha():
    for c in string.ascii_uppercase:
        print(c, end = ' ')
    print('')

# function to print lowercase alphabets
def lowerAlpha():
    for c in string.ascii_lowercase:
        print(c, end = ' ')
    print('')

# print uppercase alphabets
print('Uppercase Alphabets:')
upperAlpha()

# print lowercase alphabets
print('Lowercase Alphabets:',)
lowerAlpha()

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 in Python

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 alphabets

import string  #importing string function

# function to print all alphabets
def allAlpha():
    for c in string.ascii_letters:
        print(c, end = ' ')
    print('')

# print alphabets
print('Alphabets:')
allAlpha()

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 *