Home » Python » Python programs

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?
Submitted by Bipin Kumar, on November 02, 2019

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.

Convert character to numerical value

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.

Convert numerical value to character

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.