Python Program to Print ASCII Value of Character

Python Program to Print ASCII Value of Character

The objective of this Python post, you will see various Python examples that cover the following:

  • Python program to print ASCII value of a character
  • How to print character using ASCII value in python

Now let’s see each one by one:

1: Python program to print ASCII value of a character

  • Use a python input() function in your python program that takes an input from the user to get ASCII value.
  • Next, used ord() function to convert a character to an integer (ASCII value). This function returns the Unicode code point of that character.
  • After the end program, print the print ASCII value

Python program to print ASCII value of a character

# Program to find the ASCII value of the given character

chr = input("Please Enter Character :- ")

convert = ord(chr)

print("The ASCII value of '" + chr + "' is", convert)

Output:

Please Enter Character :- k
k
The ASCII value of 'k' is 107

2: How to print character using ASCII value in python

You can use python built-in chr() function, to get characters from their corresponding ASCII values.

Follow the steps

  • Use a python input() function in your python program that takes an input from the user to get the character from ASCII value.
  • Next, Convert user input to integer number by using python int() function.
  • Next, used chr() function to convert an ASCII value to a character.
  • After the end program, print the print character and their corresponding ASCII value.

Python program to print character using ASCII value

# Program to find the Character from ASCII value

test = input("Please Enter ASCII Value :- ")

convertToInt = int(test)

convertToAscii = chr(convertToInt)

print("The ASCII value of '" + test + "' is", convertToAscii)

Output:

Please Enter Character :- k
k
The ASCII value of 'k' is 107

Leave a Reply

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