In this tutorial, we will learn how to find the ASCII value of a character in Python. We will cover the basic concept of ASCII values and implement a function to perform the conversion.
ASCII (American Standard Code for Information Interchange) is a character encoding standard that assigns a numerical value to each character. For example, the ASCII value of 'A' is 65 and 'a' is 97.
The syntax to find the ASCII value of a character in Python is:
def char_to_ascii(char):
return ord(char)
We can create a function to find the ASCII value of a given character using Python's built-in functions.
For example,
char_to_ascii
that takes one parameter char
.ord
function to get the ASCII value of the character.def char_to_ascii(char):
return ord(char)
# Find the ASCII value of 'A'
result = char_to_ascii('A')
# Print the result
print('ASCII value of A is', result)
ASCII value of A is 65