如何获取字符的 ASCII 值

如何在Python中将字符的 ASCII值获取为int

答案

>>> ord('a')
97
>>> chr(97)
'a'
>>> chr(ord('a') + 3)
'd'
>>>
>>> unichr(97)
u'a'
>>> unichr(1234)
u'\u04d2'
>>> ord(u'あ')
12354
ord()
for ch in mystr:
    code = ord(ch)
for code in map(ord, mystr):
for code in mystr.encode('ascii'):
# If mystr is definitely str, not unicode
for code in bytearray(mystr):

# If mystr could be either str or unicode
for code in bytearray(mystr, 'ascii'):
value = input("Your value here: ")
list=[ord(ch) for ch in value]
print(list)
Your value here: qwerty
[113, 119, 101, 114, 116, 121]