如何获取列表中元素的数量items?
items
items = ["apple", "orange", "banana"] # There are 3 items.
要获取 Python 中列表中元素的数量,可以使用内置len()函数。以下是获取列表的方法items:
len()
items = ["apple", "orange", "banana"] # Get the number of elements in the list number_of_items = len(items) print(number_of_items) # Output: 3
len(items)
number_of_items
因此,在您的示例中,len(items)将返回,因为列表中3有三个元素("apple"、、"orange"和)。"banana"
3
"apple"
"orange"
"banana"