Python 类型错误函数取消订阅
我得到这种类型的错误,我不知道是什么原因造成的 我有以下代码:Python 类型错误函数取消订阅,python,function,variables,Python,Function,Variables,我得到这种类型的错误,我不知道是什么原因造成的 我有以下代码: def S(x,T,Y,ñ): u = 3 return u T = [0,1,2,3,4,5] Y = [0,1,2,3,4,5] x = 0.5 z = 0 for ñ in range(len(T)-1): if T[ñ]<=x and x<T[ñ+1]: print("correct: " + str(ñ)) print(S[x,T,Y,ñ]) 但它说:
def S(x,T,Y,ñ):
u = 3
return u
T = [0,1,2,3,4,5]
Y = [0,1,2,3,4,5]
x = 0.5
z = 0
for ñ in range(len(T)-1):
if T[ñ]<=x and x<T[ñ+1]:
print("correct: " + str(ñ))
print(S[x,T,Y,ñ])
但它说:
TypeError Traceback (most recent call last)
<ipython-input-16-98eb96968499> in <module>()
10 if T[ñ]<=x and x<T[ñ+1]:
11 print("correct: " + str(ñ))
---> 12 print(S[x,T,Y,ñ])
TypeError: 'function' object is not subscriptable
使用:
调用函数
print(S(x,T,Y,ñ)) # round parens instead of the square brackets