Python – For Loop

Python Loops

In loops, the statement are executed sequentially till the condition satisfied. The first statement in a function is executed first, followed by the second, and so on. Using Loops we can executed block of code for several times.

Python have two types of loops

StudyGyaan- Python tutorial - For loop

Python For Loop

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

# List Sequence Exaple
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 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)
Filed under: Python

No comment yet, add your voice below!


Leave a Reply