Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我不能使用列表的计数方法?_Python_Count - Fatal编程技术网

Python 为什么我不能使用列表的计数方法?

Python 为什么我不能使用列表的计数方法?,python,count,Python,Count,我使用string类的split方法,假设它返回一个列表,但它不是一个公共列表,因为我不能使用像count这样的列表方法 我尝试过使用list的count方法,但不起作用 def do_prueba(self, s): lista=s.split() len=lista.count() print(len) 我想知道名单的长度。很抱歉,我是Python新手。您没有提供计数参数。只需使用len函数获取长度,不要与您命名为len的变量混淆,因为它会覆盖内置变量: def

我使用string类的split方法,假设它返回一个列表,但它不是一个公共列表,因为我不能使用像count这样的列表方法

我尝试过使用list的count方法,但不起作用

def do_prueba(self, s):

    lista=s.split()
    len=lista.count()
    print(len)

我想知道名单的长度。很抱歉,我是Python新手。

您没有提供计数参数。只需使用len函数获取长度,不要与您命名为len的变量混淆,因为它会覆盖内置变量:

def do_prueba(self, s):
    lista=s.split()
    print(len(lista))
你搞不清楚伯爵是干什么的。mylist.countx返回列表mylist中x的出现次数。你想要的是莱恩。