【Python】常见错误

Posted by 西维蜀黍 on 2019-11-28, Last Modified on 2021-09-21

Variable

未定义的 variable

>>> len(abc)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'abc' is not defined

Dict

不存在的 Key

>>> a = {}
>>> a["s"]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
KeyError: 's'

Function

未定义的函数

>>> fun()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'fun' is not defined
>>> a = None
>>> a()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: 'NoneType' object is not callable