Print the all uppercase and lowercase alphabets in Python

Here, we are going to learn how to print the all uppercase and lowercase alphabets in Python programming language? By Bipin Kumar Last updated : January 05, 2024

To do this task, we will use the concepts of ASCII value. ASCII stands for the American Standards Code for Information exchange. It provides us the numerical value for the representation of characters. The ASCII value of uppercase letters and lowercase alphabets start from 65 to 90 and 97-122 respectively. Before going to solve this problem, we will learn a little bit about how to convert the numerical value to characters and vice-versa.

Before writing the program to print all uppercase and lowercase alphabets, you should know about the ord() and chr() methods.

The ord() function

In Python, a function ord() is used to convert the characters into a numerical value. This is an inbuilt function. Let's see the program,

# input a number
s=input('Enter the character: ')

# getting its ascii value
n=str(ord(s))

# printing the result
print('ASCII of character {} is {}.'.format(s,n))

Output

Enter the character: M
ASCII of character M is 77.

The chr() function

In Python, a function chr() is used to convert a numerical value into character. This is an inbuilt function. Let's see the program,

# input a number i.e. ascii code
n=int(input('Enter the numerical value: '))

# getting its character value
s=chr(n)

# printing the result
print('The character value of {} is {}.'.format(s,str(n)))

Output

Enter the numerical value: 77
The character value of M is 77.

Now we have learned how to convert the numerical value into character and by using its concepts we will easily solve the above problem by using the Python language.

Python program to print the all uppercase and lowercase alphabets

# printing all uppercase alphabets
print("Uppercase Alphabets are:")
for i in range(65,91): 
        ''' to print alphabets with seperation of space.''' 
        print(chr(i),end=' ')  

# printing all lowercase alphabets
print("\nLowercase Alphabets are:")
for j in range(97,123): 
        print(chr(j),end=' ')

Output

Uppercase Alphabets are:
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 are:
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

To understand the above program, you should have the basic knowledge of the following Python topics:

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.