How to get the ASCII value of a character

前端 未结 6 491
天命终不由人
天命终不由人 2020-11-22 07:04

How do I get the ASCII value of a character as an int in Python?

6条回答
  •  粉色の甜心
    2020-11-22 07:24

    ord(x) returns the Unicode of x.

    Since Unicode is an extension of ASCII, ord will also work for all things encoded by ASCII. Note that the returned value is in decimal. If you want it in another base, you can use

    bin(ord(x)) oct(ord(x)) hex(ord(x))

    as you see fit.

提交回复
热议问题