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
- Uses length to count data, bound traversal, and guard indexed access against panics.
- How deep it goes
- Explains collection and byte lengths with worked checks and iteration examples, while deferring detailed UTF-8 encoding.
- Examples
- Uses command-line arguments, race results, Unicode strings, and an average of sensor measurements.
- What you can do after
- Apply Go’s len built-in to count elements or bytes and validate slice access.
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() →
Also covered in
- Pandas Workout: 200 exercises to make you a stronger data analyst
- 100 Go Mistakes and How to Avoid Them
- Learn Go with Pocket-Sized Projects
- Python Workout, Second Edition
- The Quick Python Book, Fourth Edition
- Learn AI-Assisted Python Programming, Second Edition
- Tiny Python Projects: Learn coding and testing with puzzles and games
- Python How-To
What to know first
- PythonPython is a high-level, general-purpose, dynamically typed programming language with readable syntax and support for multiple programming paradigms.
- MapA map is an associative data structure that stores key-value associations and supports retrieving values by key.
- stringA string is a programming-language value or data type representing an ordered sequence of text characters or encoded units.
- listA list is an ordered collection of elements arranged in a sequence.
Related concepts
- listmeasures · A list is an ordered collection of elements arranged in a sequence.
- stringmeasures · A string is a programming-language value or data type representing an ordered sequence of text characters or encoded units.
- 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 associations and supports retrieving values by key.
- bufferingmeasures · Buffering temporarily stores data between processing or transfer steps, often to accommodate differences in processing rates or make operations more efficient.
Questions about len()
What is len()?
len() is a built-in operation that returns the number of elements, items, characters, bytes, or other units in a supported value.
Which Manning books explain len()?
A Pythonic Adventure: From Python basics to a working web app, Go in Action, Second Edition and Get Programming: Learn to code with Python.
What should I know before learning len()?
Manning books that teach len() usually introduce Python, Map, string and list first.
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.


