📜  ord() python (1)

📅  最后修改于: 2023-12-03 14:44:57.640000             🧑  作者: Mango

ord() in Python

In Python, ord() is a built-in function that returns an integer representing the Unicode character.

Syntax
ord(character)

character: A string of one Unicode character.

Return Value

This function returns the Unicode code point of the given Unicode character.

Example
>>> ord('A')
65
>>> ord('€')
8364
>>> ord('💻')
128187
>>> ord('க')
2949

In the example above, we use the ord() function to get the Unicode code points of the characters 'A', '€', '💻', and 'க'.

It's important to note that the ord() function only takes one argument, which must be a single character. Passing in a string with multiple characters will produce a TypeError.

>>> ord('Hello')
TypeError: ord() expected a character, but string of length 5 found

In conclusion, ord() is a simple yet helpful function in Python for working with Unicode characters.