python str转unicode和unicode转str

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Dongfnag_HU/article/details/84960231

str转Unicode:

strtypeE.decode('gbk')

unicode转str:

unicodetypeE.encode('gbk')

有时程序会报这样的错误:

Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal

那么就说明是你要对比的两个元素的类型不同,可以同过type()查看元素类型,转换成相同类型后即可。

猜你喜欢

转载自blog.csdn.net/Dongfnag_HU/article/details/84960231