Len()
len() is a built-in operation that returns the number of elements, items, characters, bytes, or other units in a supported value.
A Pythonic Adventure: From Python basics to a working web app
The Python len function returns the number of items in a container or characters in a string.
- How it is used
- Uses len() to size a menu divider automatically and to inspect strings or lists during quick REPL experiments.
- How deep it goes
- Defines len() through interactive string and list examples, then applies it in a function without covering implementation internals.
- Examples
- Demonstrates len('abcd'), len('hello'), len([1, 2, 3]), and a title-sized divider in a coffee-shop menu.
- What you can do after
- Apply it via Python to measure strings or lists and generate automatically sized menu dividers.
Read how A Pythonic Adventure: From Python basics to a working web app explains len() →
Go in Action, Second Edition
len is a Go built-in function that returns the number of bytes in a string or the number of elements in a supported collection.
- How it is used
- Measures sizes for counting and iteration, and guards indexed access to slices such as command-line arguments.
- How deep it goes
- Defines length for collections and strings, works through panic prevention and UTF-8 byte counts, but defers detailed encoding mechanics.
- Examples
- Uses a three-medalist slice that can panic and a two-character Unicode string whose length is six bytes.
- What you can do after
- Diagnose/debug with it to prevent out-of-range access and distinguish UTF-8 byte counts from visible character counts.
Get Programming: Learn to code with Python
len is a Python built-in function that returns the number of items in an object, including the number of characters in a string.
- How it is used
- Uses len() to count characters or elements while teaching strings, tuples, and lists.
- How deep it goes
- Defines len() with worked string, tuple, and list examples, then connects list length to indexing limits.
- Examples
- Uses an essay character limit, sample strings, nested tuples, grocery lists, and tuple-length quick checks.
- What you can do after
- Apply it to calculate sequence sizes and identify valid list index positions.
Read how Get Programming: Learn to code with Python explains len() →
Related concepts
- stringmeasures · A string is a programming-language value representing an ordered sequence of characters or character units as text.
- listmeasures · A list is an ordered collection of elements arranged in a sequence.
- slicinguses · Slicing selects or partitions a portion of an indexed sequence or multidimensional array, often along specified indices or dimensions.
- Mapmeasures · A map is an associative data structure that stores key-value pairs and supports retrieving values by key.
- empty slicemeasures · An empty slice is a Go slice whose length is zero, regardless of whether it has a nil descriptor or allocated backing storage.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


