python中报错Traceback (most recent call last): File “<stdin>“, line 1, in <module>TypeError: ‘str‘ obj

>>> len = 'hello'
>>> len('hello')

如果运行该代码则会报错:

Traceback (most recent call last):
  File "", line 1, in
TypeError: 'str' object is not callable

出现该错误的原因是在python中有len()该函数,但是由于我们不小心定义了该函数,则会覆盖原来的len函数,此时不论我们怎么使用len函数,都会出现报错,解决方法很简单,如下:

del len

只需要删除定义的len即可。

你可能感兴趣的:(python,java,前端)