Python Program to Find ASCII Value of a Character Last Updated : 15 Apr, 2024 Comments Improve Suggest changes Like Article Like Report Given a character, we need to find the ASCII value of that character using Python. ASCII (American Standard Code for Information Interchange) is a character encoding standard that employs numeric codes to denote text characters. Every character has its own ASCII value assigned from 0-127. Examples: Input: a Output: 97Input: DOutput: 68Python Program to Find ASCII Value of a CharacterBelow are some approaches by which we can find the ASCII value of a character in Python: Using the ord() functionUsing a dictionary mappingUsing the ord() FunctionIn this example, the function method1 returns the ASCII value of a given character using the ord() function in Python. It takes a character as input, converts it to its corresponding ASCII value, and returns it. Python3 def method1(char): return ord(char) character = 'a' print("ASCII value of", character, "is:", method1(character)) OutputASCII value of a is: 97 Using a Dictionary MappingIn this example, the function method2 creates a dictionary mapping each character in the input string to its ASCII value, then returns the ASCII value corresponding to the given character. It effectively retrieves the ASCII value of the character 'D'. Python3 def method2(char): ascii_dict = {c: ord(c) for c in char} return ascii_dict[char] character = 'D' print("ASCII value of", character, "is:", method2(character)) OutputASCII value of D is: 68 Comment More infoAdvertise with us Next Article Python Program to Find ASCII Value of a Character B bytebarde55 Follow Improve Article Tags : Python Python Programs python-basics Python-DSA Practice Tags : python Similar Reads Python program to read character by character from a file Python is a great language for file handling, and it provides built-in functions to make reading files easy with which we can read file character by character. In this article, we will cover a few examples of it.ExampleInput: GeeksOutput: G e e k sExplanation: Iterated through character by character 2 min read Python Program To Remove all control characters In the telecommunication and computer domain, control characters are non-printable characters which are a part of the character set. These do not represent any written symbol. They are used in signaling to cause certain effects other than adding symbols to text. Removing these control characters is 3 min read Python program to convert binary to ASCII In this article, we are going to see the conversion of Binary to ASCII in the Python programming language. There are multiple approaches by which this conversion can be performed that are illustrated below: Method 1: By using binascii module Binascii helps convert between binary and various ASCII-en 3 min read Python program to convert ASCII to Binary We are having a string s="Hello" we need to convert the string to its ASCII then convert the ASCII to Binary representation so that the output becomes : 01001000 01100101 01101100 01101100 0110111. To convert an ASCII string to binary we use ord() to get the ASCII value of each character and format( 2 min read Python Program for Convert characters of a string to opposite case Given a string, convert the characters of the string into the opposite case,i.e. if a character is the lower case then convert it into upper case and vice-versa. Examples: Input : geeksForgEeksOutput : GEEKSfORGeEKSInput: hello every oneOutput: HELLO EVERY ONEExample 1: Python Program for Convert ch 6 min read Like