Python For Loop – Python Programming

Python Loops

In Python For loop, the statement is executed sequentially until the condition satisfied. The first statement in a function is executed first, followed by the second, and so on. Using Loops we can execute a block of code several times.

Python For Loop Diagram

Python has two types of loops

Python For Loop

A for loop is used for iterating over a sequence. A sequence can be String, Lists, Tuples, Dictionary.

# List Sequence Example
fruits = ["apple", "banana", "cherry"]
for x in fruits:
  print(x)

# String Sequence Example
for x in "StudyGyaan":
  print(x)

Range ( ) function in Python

The range() function is python in-build function, returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.

for x in range(6):
  print(x)
Python For Loop Video Tutorial

Whats Next – Python Loop Control Statements

Share