这有效
s = 'ji?'
s.find(u'\u0101')
Run Code Online (Sandbox Code Playgroud)
我该怎么做这样的事情:
s = 'ji?'
zzz = '\u0101'
s.find(zzz)
Run Code Online (Sandbox Code Playgroud)
由于我现在使用变量,如何指示变量表示的字符串是Unicode?
由于我现在使用变量,如何指示变量表示的字符串是Unicode?
首先将它定义为Unicode字符串.
zzz = u"foo"
Run Code Online (Sandbox Code Playgroud)
或者,如果您已经在某些其他编码中使用了字符串,则将其转换为Unicode(如果字符串是非ASCII,则必须指定原始编码).
zzz = unicode(zzz, encoding="latin1")
Run Code Online (Sandbox Code Playgroud)
或者使用Python 3,其中所有字符串都是Unicode.
| 归档时间: |
|
| 查看次数: |
25514 次 |
| 最近记录: |