在Python中计数数组元素 [英] Counting array elements in Python

查看:276
本文介绍了在Python中计数数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何计算数组中元素的数量,因为与逻辑array.count(string)并不对数组中的所有元素进行计数,它只是搜索出现的字符串数.

How can I count the number of elements in an array, because contrary to logic array.count(string) does not count all the elements in the array, it just searches for the number of occurrences of string.

推荐答案

方法len()返回列表中的元素数.

The method len() returns the number of elements in the list.

语法:

len(myArray)

例如:

myArray = [1, 2, 3]
len(myArray)

输出:

3

这篇关于在Python中计数数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆