如何获取列表中的元素数量? [英] How do I get the number of elements in a list?
本文介绍了如何获取列表中的元素数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请考虑以下内容:
items = []
items.append("apple")
items.append("orange")
items.append("banana")
# FAKE METHOD:
items.amount() # Should return 3
如何获取列表items
中的元素数量?
How do I get the number of elements in the list items
?
推荐答案
len()
函数可与Python中的几种不同类型一起使用-内置类型和库类型.例如:
The len()
function can be used with several different types in Python - both built-in types and library types. For example:
>>> len([1,2,3])
3
2.x官方文档在这里: len()
正式的3.x文档在这里: len()
Official 2.x documentation is here: len()
Official 3.x documentation is here: len()
这篇关于如何获取列表中的元素数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文