这个错误是因为你尝试在一个列表对象上调用 endswith() 方法,而列表对象没有这个方法。

endswith() 方法是字符串对象的方法,用于判断一个字符串是否以指定的后缀结尾。如果你想检查列表中的元素是否以指定的后缀结尾,你需要先访问列表中的元素,然后再调用 endswith() 方法。

下面是一个示例代码,展示如何遍历列表中的元素并检查它们是否以指定的后缀结尾:

my_list = ['apple', 'banana', 'orange']

for item in my_list:
    if item.endswith('e'):
        print(item + ' ends with "e"')
    else:
        print(item + ' does not end with "e"')

请注意,这只是一个示例,你可以根据自己的需求修改代码。

使用chatglm2-6B报错 AttributeError list object has no attribute endswith

原文地址: https://www.cveoy.top/t/topic/isfC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录