类型错误:'builtin_function_or_method'对象不可订阅

问题描述 投票:-1回答:1
for x in values:
    x = header.index["NoExamples*NoFeatures"]
    print (x)

当我写这个代码时,第二行有一个错误。

"TypeError: 'builtin_function_or_method' object is not subscriptable"

你能帮帮我吗?

python typeerror
1个回答
2
投票

据推测,headersequence(例如list),而index是找到第一次出现的元素的内置方法。问题是你试图用方括号([])调用方法,这是用于索引的Python语法,而不是括号。正确的语法应该是:

x = header.index("NoExamples*NoFeatures")

这将为您提供"NoExamples*NoFeatures"序列中第一次出现的字符串header的索引。

© www.soinside.com 2019 - 2024. All rights reserved.