---
title: "len"
space: "Student Handbook"
url: "https://portal.cs17.org/student-handbook/python-manual/built-in-functions/len"
updated: "2026-10-05"
---

Returns how many items a string or list has.

## Synopsis

```python
len(value)
```

## Description

For a string, `len` counts the characters, including spaces. For a list, it counts the items.

## Parameters

| Name | Meaning |
| --- | --- |
| `value` | A string, a list, or another collection. |

## Return value

An `int`.

## Example

```python
print(len("hello"))
print(len("hi there"))
print(len(""))
print(len(["a", "b", "c"]))
```

It prints:

```text
5
8
0
3
```

## Common mistake

```python
print(len(12345))
```

Python stops with:

```text
TypeError: object of type 'int' has no len()
```

A number has no length. To count its digits, make it a string first: `len(str(12345))`.

## See also

[range](/student-handbook/python-manual/built-in-functions/range), [Indexing and slicing](/student-handbook/python-manual/lists/indexing-and-slicing)

[len in the Python documentation](https://docs.python.org/3/library/functions.html#len)
