Sunday, January 19, 2025
HomeProgrammingHow can I obtain the ASCII value of a character in Python?

How can I obtain the ASCII value of a character in Python?

In Python, you can get the ASCII value of a character using the ord() function. This function takes a single character (a string of length 1) as an argument and returns its corresponding ASCII value. Here’s an example:

See also  How to show tables in PostgreSQL? - database

char = ‘A’
ascii_value = ord(char)
print(f”The ASCII value of ‘{char}’ is {ascii_value}”)

In this case, the output will be 65, which is the ASCII value for the character ‘A’. Similarly, you can use ord() with any character to retrieve its respective ASCII code, helping with encoding and other character-based operations.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x