In the Python programming, encountered the need to convert letters to ASCII code, originally thought with an int () can directly convert the string into a shape, but int () with a default parameter, base=10, here is the decimal, if the letter appears, it will be an error, The representation range that is considered to be outside the binary.
The use of several functions is clarified by looking at the Web and Python help documents, which are recorded as follows:
Ord (c): The parameter is a string of length 1, the abbreviation character. When the parameter is a uniform object (Unicode object), returns a uniform encoding that represents the character, and returns the value of the byte when the argument is a 8-bit string. For example, Ord (' a ') returns the Shaping value 97,ord (U ' \u2020 ') returns 8224.
Chr (i): Returns a character with the ASCII code equal to the Shaping value in the parameter. For example CHR (97) Returns the character ' a ', which is the inverse of the Ord () method. The parameter must be an integer value of 0-255, or a valueerror error will be thrown.
When applying a function, it is observed that a python function is more efficient, map (function,iterable,...) Applies a function to each item iterable, and returns a list of results. map () is a Python built-in high-order function that receives a function f and a list, and then, by putting the function f on each element of the list in turn, gets a new list and returns.
Note: the map () function does not change the original list, but instead returns a new list.
With the map () function, you can convert a list to another list, just pass in the conversion function.
Because the list contains elements that can be of any type, map () can not only handle lists that contain only numeric values, but in fact it can handle lists of any type, as long as the incoming function f can handle the data type.
The conversion of letters and ASCII codes in Python