How to Get the ASCII Value of a Character in Python
In this tutorial, we will program 'How to Get the ASCII Value of a Character in Python'. We will gain a better understanding of how to get the actual ASCII value of a character. The main goal here is to use a built-in Python function named ord() that will display the actual ASCII value of a character. I will provide a sample program to demonstrate the actual coding of this tutorial.
This topic is very easy to understand; just follow the instructions I provide, and you can also do it yourself with ease. The program I will show you covers the basics of programming for getting the ASCII value of a character. I will do my best to provide you with the easiest method of creating this program, called Get the value of a character in ASCII format'. So, let's start with the coding.
Getting Started:
First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.
Creating Main Function
This is the main function of the application. The following code will display a simple GUI in terminal console that will ASCII value converter. To do this, simply copy and paste these blocks of code into the IDLE text editor.- while True:
- ret=False
- print("\n\n=============== Get the ASCII Value of a Character ===============\n\n")
- my_strings=[]
- while not my_strings:
- string = input("\nEnter a string: ")
- for char in string:
- my_strings.append(ord(char))
- if not my_strings:
- print("String must not be empty")
- else:
- print("The ASCII value is: ", my_strings)
- print("\n")
- user_input=input("\n\nTry Again? (Yes/No): ")
- if user_input.lower()=='no':
- print("Exit program.")
- break
- elif user_input.lower()=='yes':
- ret=True
- else:
- print("Wrong input.")
- ret=True
- if ret:
- continue
In the provided code, we simply enclosed the code with a while loop to allow for continuous execution of the program. To display the value of a character in ASCII, we used a formula that will provide the correct result.
Output:

The How to Get the ASCII Value of a Character in Python source code that I provide can be download below. Please kindly click the download button.
There you have it we successfully created How to Get the ASCII Value of a Character in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
More Tutorials for Python Language