python 错误大全

  • [x] 错误原因:给append函数的参数太多,append只接收一个数据项
    错误代码:
    Traceback (most recent call last):
    File "<pyshell#67>", line 1, in <module>
    case.append(1,2)
    TypeError: append() takes exactly one argument (2 given)

  • [x] 错误原因:remove、count字符串需要带上引号,不然会找不到
    错误代码:
    Traceback (most recent call last):
    File "<pyshell#55>", line 1, in <module>
    case.remove(999)
    ValueError: list.remove(x): x not in list
    Traceback (most recent call last):
    File "<pyshell#65>", line 1, in <module>
    case.count(asd)
    NameError: name 'asd' is not defined

  • [x] 错误原因:sort、sorted不支持对嵌套列表进行排序
    错误代码:
    Traceback (most recent call last):
    File "<pyshell#77>", line 1, in <module>
    case.sort()
    TypeError: '<' not supported between instances of 'list' and 'str'
    Traceback (most recent call last):
    File "<pyshell#88>", line 1, in <module>
    ca.sort()
    TypeError: '<' not supported between instances of 'list' and 'int'

  • [x] 错误原因:缺少方括号或者圆括号,本次报错是由于pop函数后面的()写成了[]
    错误代码:
    Traceback (most recent call last):
    File "C:/Users/alibaba/Desktop/python_lei.py", line 41, in <module>
    get_coach_data('james2.txt')
    File "C:/Users/alibaba/Desktop/python_lei.py", line 31, in get_coach_data
    name = temp.pop[0]
    TypeError: 'builtin_function_or_method' object is not subscriptable
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容