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
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,
Output
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,
Output
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
Output
need an explanation for this answer? contact us directly to get an explanation for this answer