ASCII value of character in python

Asked 1 years ago, Updated 1 years ago, 98 views

I want to find the ASCII value (int) of characters such as 'a', 'b' in Python.

int('a') We couldn't be together.

python ascii

2022-09-21 16:40

1 Answers

Write the ord(c) function. ord(c) returns the Unicode int value of the parameter c.

Conversely, when converting the int value to character, use the chr(i) function. chr(i) returns the ASCII code i and the corresponding string (len=1).

stringToInt = ord('a')
intToString = chr(stringToInt)

print stringToInt
print intToString

Results)

97
a

In addition, unichar(i) returns a string (len=1) with a Unicode value of i.

print unichr(97)
print unichr(1234)

Results)

a
Ӓ


2022-09-21 16:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.