将字符串转换为ASCII值python [英] Convert string to ASCII value python
本文介绍了将字符串转换为ASCII值python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将字符串转换为ASCII值?
How would you convert a string to ASCII values?
例如,"hi"将返回104105.
For example, "hi" would return 104105.
我可以分别执行ord('h')和ord('i'),但是在有很多字母的情况下会很麻烦.
I can individually do ord('h') and ord('i'), but it's going to be troublesome when there are a lot of letters.
推荐答案
您可以使用列表理解:
>>> s = 'hi'
>>> [ord(c) for c in s]
[104, 105]
这篇关于将字符串转换为ASCII值python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文