HiveBrain v1.2.0
Get Started
← Back to all entries
snippetpythonCritical

How do I get the number of elements in a list (length of a list) in Python?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howlistthenumbergetpythonlengthelements

Problem

How do I get the number of elements in the list items?

items = ["apple", "orange", "banana"]

# There are 3 items.

Solution

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

Code Snippets

>>> len([1, 2, 3])
3

Context

Stack Overflow Q#1712227, score: 2989

Revisions (0)

No revisions yet.