如何获取字符的ASCII值 [英] How to get the ASCII value of a character
问题描述
如何获取 ASCII 值,作为int href ="http://en.wikipedia.org/wiki/Python_%28programming_language%29" rel ="noreferrer"> Python ?
How do I get the ASCII value of a character as an int
in Python?
推荐答案
来自
函数ord()将获得int值
的字符.如果你想
玩完后转换回来
数字,函数chr()可以解决问题.
function ord() would get the int value
of the char. And in case you want to
convert back after playing with the
number, function chr() does the trick.
在Python 2中,还有一个 In Python 2, there is also the 在Python 3中,您可以使用 In Python 3 you can use 这篇关于如何获取字符的ASCII值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
>>> ord('a')
97
>>> chr(97)
'a'
>>> chr(ord('a') + 3)
'd'
>>>
unichr
函数,返回 Unicode 字符,序数是unichr
参数:unichr
function, returning the Unicode character whose ordinal is the unichr
argument:>>> unichr(97)
u'a'
>>> unichr(1234)
u'\u04d2'
chr
代替unichr
.chr
instead of unichr
.