chr() and ord()
Code sample link: https://replit.com/@justinjoco/python-chr-ord
These utility functions are useful for coverting unicode characters to and from their code point values. This table contains some, but not all, of the character-code point mappings: https://www.rapidtables.com/code/text/ascii-table.html
chr
The chr
function takes an integer argument and returns the appropriate unicode character for that number.
1 2 3 4 5 |
|
ord
The ord
function takes a unicode string argument and returns the corresponding code point value.
1 2 3 4 |
|
Convert a lowercase letter to an index between 0 and 25, inclusive
Use the statement ord(char) - ord("a")
1 2 3 4 |
|