len()Intermediate Examples

Returns the number of items in a container

len() with keyword arguments

Using len() with optional parameters and in iteration patterns.

python
# len() intermediate usage
print("Using len() with advanced parameters")
help(len)

len() supports additional parameters that modify its behavior.

len() in real-world code

Practical patterns using len().

python
# Common len() patterns in production code
print("len() is frequently used for data transformation")

# Example: processing a list
data = [1, 2, 3, 4, 5]
print(f"Sum: {sum(data)}")
print(f"Max: {max(data)}")
print(f"Sorted: {sorted(data, reverse=True)}")

These patterns show how len() is commonly used in production code.

Want to try these examples interactively?

Open Intermediate Playground