How to get the ASCII value of a character Python

How to get the ASCII value of a character

 

回答1

From here:

The function ord() gets the int value of the char. And in case you want to convert back after playing with the number, function chr() does the trick.

>>> ord('a')
97
>>> chr(97)
'a'
>>> chr(ord('a') + 3)
'd'
>>>

In Python 2, there was also the unichr function, returning the Unicode character whose ordinal is the unichr argument:

>>> unichr(97)
u'a'
>>> unichr(1234)
u'\u04d2'

In Python 3 you can use chr instead of unichr.


ord() - Python 3.6.5rc1 documentation

ord() - Python 2.7.14 documentation

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(16)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
历史上的今天:
2021-10-22 GIT_SSH C:\Program Files\Git\setup.ini
2021-10-22 Show SSH key file in Git Bash
2021-10-22 SSH Key - Still asking for password and passphrase
2019-10-22 Sequence contains no elements
2015-10-22 Add docking and floating support easely and quickly with DockExtender
2015-10-22 tcp断开的4次挥手
2015-10-22 tcp连接的3次握手
点击右上角即可分享
微信分享提示