python的ord()函数的反面是什么?

2024-10-02 12:30:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我发现了Python的ord()函数,它返回相应的Unicode码位值。但是什么是相反的函数,即通过int获取char值?

编辑:我是新来的,在这里找不到答案,所以决定发帖给大家,以便大家能更容易地找到答案,虽然答案很明显。然后我读了这篇-How much research effort is expected of Stack Overflow users?并意识到这是一个巨大的错误。道歉。希望它在这个意义上有用。


Tags: 函数答案编辑isunicodehowintexpected
2条回答

订单(c)

Given a string of length one, return an integer representing the Unicode code point of the character when the argument is a unicode object, or the value of the byte when the argument is an 8-bit string. For example, ord('a') returns the integer 97, ord(u'\u2020') returns 8224. This is the inverse of chr() for 8-bit strings and of unichr() for unicode objects. If a unicode argument is given and Python was built with UCS2 Unicode, then the character’s code point must be in the range [0..65535] inclusive; otherwise the string length is two, and a TypeError will be raised.

chr(i)

Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string 'a'. This is the inverse of ord(). The argument must be in the range [0..255], inclusive; ValueError will be raised if i is outside that range. See also unichr().

chr()是您要找的:

print chr(65) # will print "A"

相关问题 更多 >

    热门问题