search

Home  >  Q&A  >  body text

python如何对汉字进行编码

python如何将汉字转换成数字,对汉字进行编码
使用了ord函数,但是报错

黄舟黄舟2777 days ago692

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 10:22:06

    Chinese characters cannot be represented by ascii codes, because the ord function can only convert characters into ascii codes! If you need to compare, you can use unicode codes to compare Chinese characters;

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:22:06

    This problem disappears after changing to python3~

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:22:06

    python2

    s=u'山'
    ord(s)

    python3

    s='山'
    ord(s)

    reply
    0
  • Cancelreply