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, functionchr()
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
.
作者:Chuck Lu GitHub |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【.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次握手