FREE E LEARNING PLATFORM
☰ HOMEEXCEPTIONSOOPSJVMINTRO
×

Python Syllabus

AKTU Python Syllabus AKTU Python Freshers AKTU Python Advanced AKTU Pyton PYQ AKTU Pyton PYQS 2026 AKTU Pyton PYQS 2025 AKTU Pyton PYQS 2024

Unit I Introduction

Introduction to Python History of Python Features of Python Applications of Python Python Installation Python IDE Python Program Life Cycle First Python Program Blocks & Indentation Comments Keywords Identifiers Variables Input & Output Data Types Numeric Data Types Type Conversion Python Operators

Unit II Control Statements

if Statement if...else Statement Nested if elif Statement for Loop range() Function while Loop Nested Loops break Statement continue Statement pass Statement else with Loop

Unit III Complex Data Types

Strings String Operations String Methods String Built-in Functions Lists List Slicing List Methods List Built-in Functions Tuples Tuple Methods Dictionaries Dictionary Methods Dictionary Built-in Functions Python Built-in Functions Python Functions User Defined Functions Lambda Functions Recursive Functions

Unit IV File Handling

Introduction to File Handling open() read() readline() readlines() write() writelines() File Pointer seek() tell() File Modes

Unit V Packages & GUI

Modules Packages NumPy Pandas Matplotlib Tkinter Introduction Tkinter Widgets Button Widget Label Widget Entry Widget Frame Widget Menu Widget Event Handling Programming with IDE Tkinter Mini Project

Python Programs

100+ Solved Programs Pattern Programs File Programs Tkinter Programs

AKTU Questions

Unit I Questions Unit II Questions Unit III Questions Unit IV Questions Unit V Questions Viva Questions Python MCQs

Previous Papers

AKTU 2026 (Solved) AKTU 2025 (Solved) AKTU 2024 (Solved) AKTU 2023 (Solved) AKTU 2022 (Solved)
 


Python for Loop

The for loop in Python is used to repeat a block of code for each item in a sequence or other iterable object. It is commonly used with lists, tuples, strings, dictionaries, sets and the range() function.

Unlike a traditional counter-controlled loop, a Python for loop directly accesses each item of the iterable.

Syntax of for Loop

for variable in iterable:
    statement

The loop variable takes each value from the iterable one by one and executes the indented statements for every value.


Simple for Loop

for i in range(5):
    print(i)
Output:
0
1
2
3
4

The range(5) function generates values from 0 to 4.


for Loop with a List

fruits = ["Apple", "Banana", "Mango"]

for fruit in fruits:
    print(fruit)
Output:
Apple
Banana
Mango

The loop accesses each element of the list one at a time.


for Loop with a Tuple

numbers = (10, 20, 30, 40)

for number in numbers:
    print(number)
Output:
10
20
30
40

for Loop with a String

A string is an iterable sequence of characters. Therefore, a for loop can be used to process each character separately.

word = "Python"

for ch in word:
    print(ch)
Output:
P
y
t
h
o
n

for Loop with range()

for i in range(1, 6):
    print(i)
Output:
1
2
3
4
5

Here, the starting value is 1 and the stopping value is 6. The stopping value is not included.


for Loop with Start and Stop Values

for i in range(5, 10):
    print(i)
Output:
5
6
7
8
9

for Loop with Step Value

for i in range(2, 11, 2):
    print(i)
Output:
2
4
6
8
10

The third argument of range() specifies the step size. Here, the value increases by 2 after every iteration.


Reverse for Loop

for i in range(5, 0, -1):
    print(i)
Output:
5
4
3
2
1

Printing Even Numbers

for i in range(2, 11, 2):
    print(i)
Output:
2
4
6
8
10

Printing Odd Numbers

for i in range(1, 11, 2):
    print(i)
Output:
1
3
5
7
9

Calculating Sum using for Loop

numbers = [10, 20, 30, 40, 50]
total = 0

for number in numbers:
    total = total + number

print("Sum =", total)
Output:
Sum = 150

Finding the Largest Number

numbers = [12, 45, 23, 67, 34]

largest = numbers[0]

for number in numbers:
    if number > largest:
        largest = number

print("Largest =", largest)
Output:
Largest = 67

Counting Elements using for Loop

numbers = [10, 20, 30, 40, 50]
count = 0

for number in numbers:
    count = count + 1

print("Number of elements =", count)
Output:
Number of elements = 5

for Loop with if Statement

A for loop can contain an if statement to perform conditional processing during each iteration.

numbers = [10, 15, 20, 25, 30]

for number in numbers:
    if number % 2 == 0:
        print(number)
Output:
10
20
30

for Loop with else

Python allows an else block to be associated with a for loop. The else block executes when the loop completes normally.

for i in range(5):
    print(i)
else:
    print("Loop completed")
Output:
0
1
2
3
4
Loop completed

Nested for Loop

A nested for loop is a for loop inside another for loop.

for i in range(1, 4):
    for j in range(1, 4):
        print(i, j)
Output:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

Multiplication Table using for Loop

number = 5

for i in range(1, 11):
    print(number, "x", i, "=", number * i)
Output:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

Using break in for Loop

The break statement terminates the loop immediately.

for i in range(1, 10):
    if i == 5:
        break
    print(i)
Output:
1
2
3
4

Using continue in for Loop

The continue statement skips the current iteration and moves to the next iteration.

for i in range(1, 6):
    if i == 3:
        continue
    print(i)
Output:
1
2
4
5

Using pass in for Loop

The pass statement does nothing. It can be used as a placeholder where a statement is syntactically required.

for i in range(5):
    if i == 2:
        pass
    print(i)
Output:
0
1
2
3
4

Practical Example: Factorial using for Loop

number = 5
factorial = 1

for i in range(1, number + 1):
    factorial = factorial * i

print("Factorial =", factorial)
Output:
Factorial = 120

Practical Example: Count Vowels

text = "Python Programming"
count = 0

for ch in text.lower():
    if ch in "aeiou":
        count = count + 1

print("Number of vowels =", count)
Output:
Number of vowels = 4

Practical Example: Reverse a String

text = "Python"
reverse_text = ""

for ch in text:
    reverse_text = ch + reverse_text

print(reverse_text)
Output:
nohtyP

Practical Example: Pattern using for Loop

for i in range(1, 6):
    print("*" * i)
Output:
*
**
***
****
*****

for Loop with Dictionary

student = {
    "name": "Rahul",
    "age": 20,
    "marks": 85
}

for key in student:
    print(key, ":", student[key])
Output:
name : Rahul
age : 20
marks : 85

for Loop with Dictionary Items

student = {
    "name": "Rahul",
    "marks": 85
}

for key, value in student.items():
    print(key, ":", value)
Output:
name : Rahul
marks : 85

for Loop with Set

numbers = {10, 20, 30}

for number in numbers:
    print(number)

A set is unordered, so the order in which its elements are displayed should not be assumed.


Important Points

  • The for loop is used to iterate over an iterable.
  • Lists, tuples, strings, dictionaries, sets and ranges can be used with a for loop.
  • The loop variable receives one item at a time.
  • Indentation defines the body of the loop.
  • The range() function is commonly used with for loops.
  • break terminates the loop.
  • continue skips the current iteration.
  • pass acts as a placeholder.
  • A for loop can contain an if statement.
  • Python also supports nested for loops.
Key Point: A Python for loop repeatedly executes a block of code for each item in an iterable. It is one of the most commonly used looping statements in Python.