CKTIS / Python
ord()
Returns the Unicode code point of a single-character string.
Version: Python 3.14; repository image, production runtime not attested
Syntax
ord(c, /)Returns the Unicode code point of a single-character string.
A string containing two code points is rejected even when a renderer displays them as one accented glyph.
A one-code-point string gives the code point as an int; a single byte in bytes or bytearray gives its numeric value as well. The letter A maps to 65. The decomposed e plus combining acute can look like one glyph yet has length two, so it raises TypeError.
assert ord("A") == 65 and ord(b"A") == 65
assert len("e\u0301") == 2 and ord("é") == 233
Examples
print(ord("A"))
try:
ord("e\u0301")
except TypeError as error:
print(type(error).__name__)
Result
65 TypeError
A one-code-point string gives the code point as an int; a single byte in bytes or bytearray gives its numeric value as well. The letter A maps to 65. The decomposed e plus combining acute can look like one glyph yet has length two, so it raises TypeError.