Python Programming

Python Study Material

Master Python step-by-step with our structured class-wise lessons, practice exercises, and assessments.

Class 01

Python Fundamentals

Learn the building blocks of Python programming — variables, data types, and operators.

📖 Study Material

📝 1.1 Introduction to Python +

Python is a high-level, interpreted programming language known for its simplicity and readability. Created by Guido van Rossum in 1991, Python has become one of the most popular languages worldwide.

Why Learn Python?
  • Easy to learn and read — great for beginners
  • Used in Web Development, Data Science, AI, Automation
  • Large community and extensive libraries
  • High demand in the job market
Example: Your First Program
# This is your first Python program
print("Hello, World!")
print("Welcome to UKTekIndia!")

# Output:
# Hello, World!
# Welcome to UKTekIndia!
📝 1.2 Variables & Data Types +

Variables are containers for storing data. In Python, you don't need to declare the type — Python figures it out automatically.

Basic Data Types:
  • int — Integer numbers: 5, -3, 100
  • float — Decimal numbers: 3.14, -0.5
  • str — Text strings: "Hello", 'Python'
  • bool — True or False
Example: Variables
# Creating variables
name = "Rahul"          # str
age = 25                # int
height = 5.9            # float
is_student = True       # bool

# Printing variables
print(f"Name: {name}")
print(f"Age: {age}")
print(f"Type of age: {type(age)}")

# Output:
# Name: Rahul
# Age: 25
# Type of age: <class 'int'>
📝 1.3 Operators in Python +

Operators are symbols that perform operations on variables and values.

Types of Operators:
  • Arithmetic: +, -, *, /, //, %, **
  • Comparison: ==, !=, >, <, >=, <=
  • Logical: and, or, not
  • Assignment: =, +=, -=, *=
Example: Operators
# Arithmetic operators
a = 10
b = 3
print(a + b)   # 13
print(a - b)   # 7
print(a * b)   # 30
print(a / b)   # 3.333...
print(a // b)  # 3 (floor division)
print(a % b)   # 1 (remainder)
print(a ** b)  # 1000 (power)

# Comparison
print(a > b)   # True
print(a == b)  # False
📝 1.4 Input & Output +

Python uses input() to take user input and print() to display output.

Example: Input/Output
# Taking input from user
name = input("Enter your name: ")
age = int(input("Enter your age: "))

# Displaying output
print(f"Hello {name}! You are {age} years old.")

# String formatting methods
print("Name: %s, Age: %d" % (name, age))
print("Name: {}, Age: {}".format(name, age))

📝 Class 1 Exam

Test your understanding of Python Fundamentals. You need 70% to pass.

Q1

What is the output of print(type(3.14))?

Q2

Which operator is used for floor division in Python?

Q3

What will x = 5; x += 3; print(x) output?

Q4

Which function is used to take user input in Python?

Q5

What is the correct way to create a variable in Python?

Class 02

Control Flow & Loops

Learn how to control the flow of your program using conditions and loops.

📖 Study Material

📝 2.1 If / Elif / Else Statements +

Conditional statements allow you to execute code based on whether a condition is True or False.

Example: If/Elif/Else
age = 18

if age >= 18:
    print("You are an adult!")
elif age >= 13:
    print("You are a teenager!")
else:
    print("You are a child!")

# Nested condition
marks = 85
if marks >= 90:
    grade = "A+"
elif marks >= 80:
    grade = "A"
elif marks >= 70:
    grade = "B"
else:
    grade = "C"
print(f"Your grade: {grade}")
📝 2.2 For Loops +

The for loop iterates over a sequence (list, string, range, etc.).

Example: For Loops
# Looping through a range
for i in range(1, 6):
    print(f"Number: {i}")

# Looping through a list
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(f"I like {fruit}")

# Using enumerate
for index, fruit in enumerate(fruits):
    print(f"{index}: {fruit}")
📝 2.3 While Loops +

The while loop repeats as long as a condition is True.

Example: While Loops
# Basic while loop
count = 1
while count <= 5:
    print(f"Count: {count}")
    count += 1

# While with break
while True:
    answer = input("Type 'quit' to exit: ")
    if answer == "quit":
        break
    print(f"You typed: {answer}")
📝 2.4 Break, Continue & Pass +

These keywords control loop execution flow.

  • break — Exits the loop immediately
  • continue — Skips current iteration
  • pass — Does nothing (placeholder)
Example: Break & Continue
# Using break
for i in range(10):
    if i == 5:
        break
    print(i)  # 0, 1, 2, 3, 4

# Using continue
for i in range(10):
    if i % 2 == 0:
        continue
    print(i)  # 1, 3, 5, 7, 9

📝 Class 2 Exam

Test your knowledge of Control Flow & Loops. You need 70% to pass.

Q1

What keyword is used to skip the current iteration in a loop?

Q2

What is the output of for i in range(3): print(i)?

Q3

Which keyword exits a loop completely?

Q4

What does elif stand for?

Q5

How many times does while True: break execute the loop body?

Class 03

Functions & Modules

Learn to write reusable code with functions and organize code with modules.

📖 Study Material

📝 3.1 Defining Functions +

Functions are blocks of reusable code that perform a specific task.

Example: Functions
# Basic function
def greet(name):
    return f"Hello, {name}!"

print(greet("Rahul"))  # Hello, Rahul!

# Default parameters
def power(base, exp=2):
    return base ** exp

print(power(3))     # 9
print(power(3, 3))  # 27

# Multiple return values
def get_stats(numbers):
    return min(numbers), max(numbers), sum(numbers)/len(numbers)

low, high, avg = get_stats([10, 20, 30, 40])
print(f"Min: {low}, Max: {high}, Avg: {avg}")
📝 3.2 *args and **kwargs +

Use *args for variable positional arguments and **kwargs for keyword arguments.

Example: *args, **kwargs
# *args - variable arguments
def total(*args):
    return sum(args)

print(total(1, 2, 3, 4))  # 10

# **kwargs - keyword arguments
def info(**kwargs):
    for key, value in kwargs.items():
        print(f"{key}: {value}")

info(name="Priya", age=22, city="Kolkata")
📝 3.3 Lambda Functions +

Lambda functions are small anonymous functions defined in a single line.

Example: Lambda
# Lambda function
square = lambda x: x ** 2
print(square(5))  # 25

# Lambda with sorted
students = [("Rahul", 85), ("Priya", 92), ("Amit", 78)]
sorted_students = sorted(students, key=lambda s: s[1], reverse=True)
print(sorted_students)
# [('Priya', 92), ('Rahul', 85), ('Amit', 78)]

📝 Class 3 Exam

Test your knowledge of Functions & Modules.

Q1

What keyword is used to define a function in Python?

Q2

What does *args accept?

Q3

What is the output of (lambda x: x*2)(5)?

Q4

What keyword returns a value from a function?

Class 04

OOP Concepts

Master Object-Oriented Programming — classes, objects, inheritance, and more.

📖 Study Material

📝 4.1 Classes & Objects +

A class is a blueprint for creating objects. Objects have properties (attributes) and behaviors (methods).

Example: Classes
class Student:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def introduce(self):
        return f"Hi, I'm {self.name}, age {self.age}"

# Creating objects
s1 = Student("Rahul", 20)
s2 = Student("Priya", 22)
print(s1.introduce())  # Hi, I'm Rahul, age 20
📝 4.2 Inheritance +

Inheritance allows a child class to inherit properties from a parent class.

Example: Inheritance
class Animal:
    def __init__(self, name):
        self.name = name

    def speak(self):
        return "..."

class Dog(Animal):
    def speak(self):
        return f"{self.name} says: Woof!"

class Cat(Animal):
    def speak(self):
        return f"{self.name} says: Meow!"

dog = Dog("Buddy")
cat = Cat("Whiskers")
print(dog.speak())  # Buddy says: Woof!
print(cat.speak())  # Whiskers says: Meow!

📝 Class 4 Exam

Test your OOP knowledge.

Q1

What method is called when a new object is created?

Q2

What does self refer to in a class?

Q3

When a child class overrides a parent method, it's called?

Class 05

Data Structures

Master Python's built-in data structures — Lists, Dictionaries, Sets, and Tuples.

📖 Study Material

📝 5.1 Lists & Tuples +

Lists are mutable ordered collections. Tuples are immutable.

Example: Lists & Tuples
# Lists (mutable)
fruits = ["apple", "banana", "cherry"]
fruits.append("mango")
fruits.remove("banana")
print(fruits)  # ['apple', 'cherry', 'mango']

# List comprehension
squares = [x**2 for x in range(1, 6)]
print(squares)  # [1, 4, 9, 16, 25]

# Tuples (immutable)
coords = (10, 20)
print(coords[0])  # 10
📝 5.2 Dictionaries & Sets +

Dictionaries store key-value pairs. Sets store unique values.

Example: Dicts & Sets
# Dictionary
student = {"name": "Rahul", "age": 20, "grade": "A"}
print(student["name"])  # Rahul
student["city"] = "Kolkata"  # Add new key

# Sets
numbers = {1, 2, 3, 4, 5, 5, 3}
print(numbers)  # {1, 2, 3, 4, 5} - unique only

# Set operations
a = {1, 2, 3}
b = {3, 4, 5}
print(a | b)  # Union: {1, 2, 3, 4, 5}
print(a & b)  # Intersection: {3}

📝 Class 5 Exam

Test your Data Structures knowledge.

Q1

Which data type is immutable?

Q2

What method adds an element to the end of a list?

Q3

What does {} create in Python?

Class 06

File Handling & Error Handling

Learn to work with files and handle errors gracefully in Python.

📖 Study Material

📝 6.1 File Operations +

Python provides built-in functions to read, write, and manage files.

Example: File Handling
# Writing to a file
with open("notes.txt", "w") as f:
    f.write("Hello, World!\n")
    f.write("Python is awesome!")

# Reading from a file
with open("notes.txt", "r") as f:
    content = f.read()
    print(content)

# Appending to a file
with open("notes.txt", "a") as f:
    f.write("\nNew line added!")
📝 6.2 Try / Except / Finally +

Error handling prevents your program from crashing unexpectedly.

Example: Error Handling
try:
    number = int(input("Enter a number: "))
    result = 10 / number
    print(f"Result: {result}")
except ValueError:
    print("Error: Please enter a valid number!")
except ZeroDivisionError:
    print("Error: Cannot divide by zero!")
finally:
    print("This always executes.")

📝 Class 6 Exam

Test your File Handling & Error Handling knowledge.

Q1

What mode opens a file for writing (overwrites existing)?

Q2

Which block always executes in a try/except?

Q3

What does the with statement do for files?

UKTekIndia Assistant
Online