Python For Loop Syntax and Examples

In computer science, a for-loop (or simply for loop) is a control flow statement for specifying iteration, which allows code to be executed repeatedly.

Table of Contents
Syntax

for item in sequence:
    execute expression
Examples

Basic:

for i in range(1,6):
    print(i)

Enumerate:

items = ["apple","banana","egg"]

for index, item in enumerate(items):
    print(index,item)