如何在Python中将字符转换为整数,反之亦然?


Answers:



37
>>> ord('a')
97
>>> chr(97)
'a'

您在另一个人还没有参加500多个投票之前1分钟发布了此答案...
Oriont

14

ord和chr


71
关于这个答案,我最喜欢的部分是他们无意间编写了有效的Python行。
ArtOfWarfare

1
print ((ord and chr)(0O041))
AndyB
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.