|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
ss = [12, 3, 33, 5, 4]
w = [ord(a) for a in ss.index(2)]
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
w = [ord(a) for a in ss.index(2)]
ValueError: 2 is not in list
w = [ord(a) for a in a in ss.index(2)]
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
w = [ord(a) for a in a in ss.index(2)]
NameError: name 'a' is not defined
加in显示a 定义错误,不加又没有2这个元素
本帖最后由 isdkz 于 2023-1-31 16:42 编辑
ord 是获取字符的 unicode 码值的,你那个 ss.index(2) 不是字符串,用 str 转成字符串
而且 2 这个元素不在列表中,用 index 会报错
- ss = [12, 3, 33, 5, 4]
- w = [ord(a) for a in str(ss.index(33))]
复制代码
|
|