Convert int to ASCII and back in Python

前端 未结 5 2112
庸人自扰
庸人自扰 2020-12-04 06:08

I\'m working on making a URL shortener for my site, and my current plan (I\'m open to suggestions) is to use a node ID to generate the shortened URL. So, in theory, node 26

5条回答
  •  臣服心动
    2020-12-04 06:41

    ASCII to int:

    ord('a')
    

    gives 97

    And back to a string:

    • in Python2: str(unichr(97))
    • in Python3: chr(97)

    gives 'a'

提交回复
热议问题