Python(TypeError:Add不支持的操作数类型:“ undefined”和“ str”)

弗雷德

我是python的新手。请告诉我我犯了什么错误。

list = [1,2,3,4]
print "elements:"
for a in list:
    print(a)
num=int(input("pick 1 element"))
print num + " is " + list.index(num)

输出:

elements:
1
2
3
4
pick 1 element
2
TypeError: unsupported operand type(s) for Add: 'undefined' and 'str'

如果我做到num=strValueError: list.index(x): x not in list

mdml

尝试:

print str(num) + " is " + str(list.index(num))

您的问题是num输出时需要为字符串,但int索引到列表时则需要为字符串更简单的是,您可以利用Pythonprint函数功能为您完成转换:

print num, "is", list.index(num)

另外,请不要命名您的list list,这是Python的内置函数。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

+不支持的操作数类型:“ int”和“ str”

来自分类Dev

Python(TypeError:Add不支持的操作数类型:“ undefined”和“ str”)

来自分类Dev

总和函数prob TypeError:+不支持的操作数类型:'int'和'str'

来自分类Dev

Python TypeError:+不支持的操作数类型:'NoneType'和'str'

来自分类Dev

TypeError:+不支持的操作数类型:'StringVar'和'str'//创建文本文件

来自分类Dev

Python--:“ int”和“ str”不支持的操作数类型

来自分类Dev

TypeError:-:“ str”和“ int” Python不支持的操作数类型

来自分类Dev

+不支持的操作数类型:“ WindowsPath”和“ str”

来自分类Dev

神经网络TypeError:+ =不支持的操作数类型:'Dense'和'str'

来自分类Dev

TypeError:/不支持的操作数类型:'str'和'str'django setting.py

来自分类Dev

+不支持的操作数类型(“ str”和“ int”)

来自分类Dev

TypeError:+不支持的操作数类型:“标记”和“ str”

来自分类Dev

python错误; +不支持的操作数类型:“ int”和“ str”

来自分类Dev

TypeError:+不支持的操作数类型:“ int”和“ str”值

来自分类Dev

+不支持的操作数类型:'NoneType'和'str'和'int'

来自分类Dev

Python 2.7 TypeError:%不支持的操作数类型:“ None type”和str

来自分类Dev

TypeError:+ =不支持的操作数类型:“ int”和“ str”

来自分类Dev

TypeError:div不支持的操作数类型:“ str”和“ int” [第14行]

来自分类Dev

Python 3 TypeError:**或pow()不支持的操作数类型:“ str”和“ int”

来自分类Dev

Python27 TypeError:类型不支持的操作数+ ='int'和'str'

来自分类Dev

TypeError: 不支持的操作数类型 /: 'int' 和 'str' 制作网格时

来自分类Dev

两个浮点数抛出 TypeError: 不支持的操作数类型 +: 'float' 和 'str'

来自分类Dev

类型错误:不支持 + 的操作数类型:'NoneType' 和 'str'/基本转换

来自分类Dev

Pandas Groupby : TypeError: 不支持的操作数类型 -: 'str' 和 'str'

来自分类Dev

如何修复 TypeError: 不支持的操作数类型 +: 'int' 和 'str'

来自分类Dev

- 不支持的操作数类型:“str”和“str”

来自分类Dev

如何修复 [类型错误:+= 不支持的操作数类型:'builtin_function_or_method' 和 'str'] Python 中的错误

来自分类Dev

类型错误:不支持 str 和 int 的操作数类型

来自分类Dev

TypeError: 不支持 & 的操作数类型:'str' 和 'str' 如何解决

Related 相关文章

  1. 1

    +不支持的操作数类型:“ int”和“ str”

  2. 2

    Python(TypeError:Add不支持的操作数类型:“ undefined”和“ str”)

  3. 3

    总和函数prob TypeError:+不支持的操作数类型:'int'和'str'

  4. 4

    Python TypeError:+不支持的操作数类型:'NoneType'和'str'

  5. 5

    TypeError:+不支持的操作数类型:'StringVar'和'str'//创建文本文件

  6. 6

    Python--:“ int”和“ str”不支持的操作数类型

  7. 7

    TypeError:-:“ str”和“ int” Python不支持的操作数类型

  8. 8

    +不支持的操作数类型:“ WindowsPath”和“ str”

  9. 9

    神经网络TypeError:+ =不支持的操作数类型:'Dense'和'str'

  10. 10

    TypeError:/不支持的操作数类型:'str'和'str'django setting.py

  11. 11

    +不支持的操作数类型(“ str”和“ int”)

  12. 12

    TypeError:+不支持的操作数类型:“标记”和“ str”

  13. 13

    python错误; +不支持的操作数类型:“ int”和“ str”

  14. 14

    TypeError:+不支持的操作数类型:“ int”和“ str”值

  15. 15

    +不支持的操作数类型:'NoneType'和'str'和'int'

  16. 16

    Python 2.7 TypeError:%不支持的操作数类型:“ None type”和str

  17. 17

    TypeError:+ =不支持的操作数类型:“ int”和“ str”

  18. 18

    TypeError:div不支持的操作数类型:“ str”和“ int” [第14行]

  19. 19

    Python 3 TypeError:**或pow()不支持的操作数类型:“ str”和“ int”

  20. 20

    Python27 TypeError:类型不支持的操作数+ ='int'和'str'

  21. 21

    TypeError: 不支持的操作数类型 /: 'int' 和 'str' 制作网格时

  22. 22

    两个浮点数抛出 TypeError: 不支持的操作数类型 +: 'float' 和 'str'

  23. 23

    类型错误:不支持 + 的操作数类型:'NoneType' 和 'str'/基本转换

  24. 24

    Pandas Groupby : TypeError: 不支持的操作数类型 -: 'str' 和 'str'

  25. 25

    如何修复 TypeError: 不支持的操作数类型 +: 'int' 和 'str'

  26. 26

    - 不支持的操作数类型:“str”和“str”

  27. 27

    如何修复 [类型错误:+= 不支持的操作数类型:'builtin_function_or_method' 和 'str'] Python 中的错误

  28. 28

    类型错误:不支持 str 和 int 的操作数类型

  29. 29

    TypeError: 不支持 & 的操作数类型:'str' 和 'str' 如何解决

热门标签

归档