use*_*192 1 python syntax typeerror
代码为什么会这样
print("Average =" (sum/count))
Run Code Online (Sandbox Code Playgroud)
产生类型错误而不是语法错误,看到逗号丢失了吗?
谢谢.
Python将其()
视为函数调用; 字符串不可调用,导致TypeError
:
>>> "somestring"(42)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
Run Code Online (Sandbox Code Playgroud)
在Python中,一切都是对象; 函数也是对象,任何对象都可以实现一个__call__
方法,使每个对象都可以调用.Python不会知道字符串对象在运行时才可调用,因此这不是语法错误.