Convert string to ASCII value python

后端 未结 8 1697
深忆病人
深忆病人 2020-12-07 22:43

How would you convert a string to ASCII values?

For example, \"hi\" would return 104105.

I can individually do ord(\'h\') and ord(\'i\'), but it\'s going to

8条回答
  •  旧巷少年郎
    2020-12-07 23:00

    If you want your result concatenated, as you show in your question, you could try something like:

    >>> reduce(lambda x, y: str(x)+str(y), map(ord,"hello world"))
    '10410110810811132119111114108100'
    

提交回复
热议问题