Syntax

Python Loop with Index Syntax

In Python, loop with index: gets index and value while looping — for i, item in enumerate(items):

Quick Answer

Syntax
for i, item in enumerate(items):
PythonSyntax

Loop with Index

Code example
for i, item in enumerate(items):

Gets index and value while looping.

Learn More

How to loop with index in Python

  1. Open your Python file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Python Loop with Index Syntax

Use for i, item in enumerate(items):.

Related Syntax References

Frequently asked questions

What is the Python syntax for loop with index?

Use this pattern: for i, item in enumerate(items):

Can I copy this Python code example?

Yes. Use Copy code and adapt the example to your program.

Is this Python syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify