Home > Q&A > body text
python如何将汉字转换成数字,对汉字进行编码使用了ord函数,但是报错
大家讲道理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;
高洛峰2017-04-18 10:22:06
This problem disappears after changing to python3~
PHP中文网2017-04-18 10:22:06
python2
s=u'山' ord(s)
python3
s='山' ord(s)