# How to number and output objects using Python enumerate()

Python `enumerate()` is used to output an input as an enumeration object. You can use the integrated function to number strings and lists, among other things.

## What is Python `enumerate()`?

The Python function `enumerate()` is used to **turn an input into an enumeration**. The objects, which can also be strings or [Python tuples](https://www.ionos.com/digitalguide/websites/web-development/python-tuples/), for example, are each assigned a counter. The enumeration is consecutive and starts at “0” by default. The function is included in the [programming language](https://www.ionos.com/digitalguide/websites/web-development/web-programming-languages/) by default.

## What is the syntax and parameter of Python `enumerate()`?

The syntax of Python `enumerate()` looks like this:

```python
enumerate(iterable, start)
```

It has two parameters:

- `iterable`: “iterable” is an object or a sequence that can be executed in a loop. This parameter is placed in front of the enumeration later on. It is mandatory.
- `start`: This is an optional parameter. You can use it to determine from which numerical value the numbering should start. Its default value is “0”.

## Example of an enumeration with `enumerate()`

To illustrate how this works, let’s choose a simple example with four different colors. We number these using Python `enumerate()`. The corresponding code looks like this:

```python
colors = ['Blue', 'Red', 'Yellow', 'Orange']
sequence = enumerate(colors)
print(list(sequence))
```

This is how we get this output:

```python
[(0, 'Blue'), (1, 'Red'), (2, 'Yellow'), (3, 'Orange')]
```

## Python `enumerate()` with a start index

As we have not specified a start index, the enumeration starts at “0”. To change this, we add the **parameter “start”** with the value “1” to Python `enumerate()`. To do this, we slightly change the code from above:

```python
colors = ['Blue', 'Red', 'Yellow', 'Orange']
sequence = enumerate(colors, 1)
print(list(sequence))
```

This makes the output look a little nicer:

```python
[(1, 'Blue'), (2, 'Red'), (3, 'Yellow'), (4, 'Orange')]
```

However, you can adjust the start index as you wish so that the enumeration can also begin with any other value.

## `Enumerate()` function with a `for` loop

In combination with a [for loop](https://www.ionos.com/digitalguide/websites/web-development/python-for-loop/), we can combine the use of Python `enumerate()` **with and without start index**. For the first loop, we don’t need the “start” parameter. The count therefore starts at “0”. For the second loop, we include the parameter with the starting point “5”. Therefore, this count starts from here. With the `"\n"` label, we instruct the system to create a new line each time so that it is a little clearer. This is the code for this combination:

```python
colors = ['Blue', 'Red', 'Yellow', 'Orange']
for sequence in enumerate(colors):
    print(sequence)
    print("\n")
print("It continues from 5")        
for sequence in enumerate(colors, 5):
    print(sequence)
    print("\n")
```

Our output now looks like this:

```python
(0, 'Blue')
(1, 'Red')
(2, 'Yellow')
(3, 'Orange')
It continues from 5
(5, 'Blue')
(6, 'Red')
(7, 'Yellow')
(8, 'Orange')
```

## How to enumerate strings with Python `enumerate()`

As the name suggests, Python `enumerate()` is also the right choice if you want to enumerate a string. This breaks down the string **into its individual parts and numbers them**. This is what the code looks like:

```python
string = "example"
for x in enumerate(string, 1):
    print(x)
```

This is the right output:

```python
(1, 'e')
(2, 'x')
(3, 'a')
(4, 'm')
(5, 'p')
(6, 'l')
(7, 'e')
```

Tip The best solution for websites and apps: With [Deploy Now](https://www.ionos.com/hosting/deploy-now "Deploy Now from IONOS") from IONOS, you can deploy your web projects directly via GitHub. Not only do you benefit from fair pricing, but you can also tailor the setup perfectly to your needs. Our experts are waiting to advise you now!


This is a markdown version of: [https://www.ionos.com/digitalguide/websites/web-development/python-enumerate/](https://www.ionos.com/digitalguide/websites/web-development/python-enumerate/) for AI/LLM consumption.