May 10, 2021 Python2
Scene:
Convert characters to ascii or unicode encoding
During the conversion process, be careful to use the ord and chr methods
>>> print(ord('a'))
97
>>> print(chr(97))
a
>>>
Sometimes you need to reverse to use:
>>> print(str(ord('a')))
97
>>> print(chr(ord('a')))
a
>>>
This is a time to note the difference between str() and chr(): str is a string that converts the returned object directly into a string, and chr is a string that converts the returned object into a corresponding ascii code.