Python - 如何在作为变量的Unicode字符上执行字符串查找?

Ste*_*eve 8 python unicode

这有效

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?

kin*_*all 7

由于我现在使用变量,如何指示变量表示的字符串是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.