Python strip()unicode字符串?

nep*_*pwk 5 python string unicode strip

如何在unicode字符串上使用strip()等字符串方法?并且你不能访问像oridnary字符串一样的unicode字符串的字符?(例如:mystring [0:4])

Gab*_*aru 8

它正常工作,只要它们实际上unicode不是str(注意:每个字符串文字都必须在前面u,如本例所示):

>>> a = u"co?ofan?"
>>> a
u'co\u021bofan\u0103'
>>> a[-1]
u'\u0103'
>>> a[2]
u'\u021b'
>>> a[3]
u'o'
>>> a.strip(u'?')
u'co\u021bofan'
Run Code Online (Sandbox Code Playgroud)