liveBook · Manning

Len()

len() is a built-in operation that returns the number of elements, items, characters, bytes, or other units in a supported value.

How 3 Manning books explain it

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.

Read how Go in Action, Second Edition explains len() →

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

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.