-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms
The for
loop in Python is used to iterate over a sequence (like a list, tuple, string, or range).
for variable in sequence:
# code block
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
for letter in "Python":
print(letter)
range()
Functionfor i in range(5):
print(i)
Output:0 1 2 3 4
range()
for i in range(2, 6):
print(i)
Output:2 3 4 5
range()
for i in range(1, 10, 2):
print(i)
Output:1 3 5 7 9
for i in range(3):
print(i)
else:
print("Finished")
colors = ["red", "green"]
objects = ["car", "bike"]
for color in colors:
for obj in objects:
print(color, obj)
for i in range(5):
if i == 3:
break
print(i)
for i in range(5):
if i == 2:
continue
print(i)
Practice using for
loop with range
, lists, strings, and control flow.
Q1. Write a Python program to print numbers from 1 to 10 using a for
loop.
Q2. Write a Python program to loop through a list of names and print each name.
Q3. Write a Python program to loop through a string and count the number of vowels.
Q4. Write a Python program to print all even numbers between 1 and 20.
Q5. Write a Python program to print each character in the word "Python"
using a for
loop.
Q6. Write a Python program to use range()
to print numbers from 5 to 15.
Q7. Write a Python program to print the multiplication table of 4 using a for
loop.
Q8. Write a Python program to use nested for
loops to print all combinations of numbers 1–3 and letters A–C.
Q9. Write a Python program to use break
to stop a loop when the number reaches 5.
Q10. Write a Python program to use continue
to skip number 3 in a loop from 1 to 5.
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms