Python常见错误(1)

来源:互联网 发布:跟奥巴马一起编程 15 编辑:程序博客网 时间:2024/06/01 10:32

1. 变量覆盖,导致出错

str = 'hello'tmp = ''for s in str:    tmp += ord(str(s))print(tmp)

显示错误:
TypeError: 'str' object is not callable

问题在于第一行,习惯性命名变量为str,将python的关键字str覆盖了。

0 0