python中有两种字符串对象,即str和unicode。
一个简单的演示:
s1 = ‘abcdefg’u1 = u’abcdefg’print s1print u1type(s1)type(u1)
返回得到:
abcdefgabcdefg<type ‘str’><type ‘unicode’>
可见,虽然s1和u1两个变量看似内容和输出一致,但是类型却完全不同。
它们二者的方法适用性也可能完全不同。当有报错提示,
ValueError: Expected a bytes object, not a unicode object
说明不能传入unicode对象,需要将unicode转换为str对象.