0% found this document useful (0 votes)
3 views33 pages

Complete Python Course Book

The Complete Python Course Book is a comprehensive guide that takes learners from Python fundamentals to advanced programming concepts. It includes practical exercises and covers a wide range of topics such as data types, functions, object-oriented programming, and database basics. The book is structured in stages to facilitate progressive learning and includes mini-projects for hands-on practice.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views33 pages

Complete Python Course Book

The Complete Python Course Book is a comprehensive guide that takes learners from Python fundamentals to advanced programming concepts. It includes practical exercises and covers a wide range of topics such as data types, functions, object-oriented programming, and database basics. The book is structured in stages to facilitate progressive learning and includes mini-projects for hands-on practice.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Complete Python Course Book

Beginner to Advanced • Original Learning Guide

This book is an original study guide designed to take a learner from Python fundamentals to practical
programming. It is not a reproduction of any third-party website or textbook.

How to use this book: Read each chapter, type the examples yourself, change the examples, and
complete additional exercises. Programming is learned best through practice.
Table of Contents
1. Introduction to Python

2. Variables and Data Types

3. Input and Output

4. Operators

5. Strings

6. Lists

7. Tuples

8. Sets

9. Dictionaries

10. Conditional Statements

11. Loops

12. Functions

13. Lambda Functions

14. Recursion

15. Modules and Packages

16. Exception Handling

17. File Handling

18. Object-Oriented Programming

19. Inheritance

20. Iterators and Generators

21. List Comprehension

22. Regular Expressions

23. JSON

24. Dates and Time

25. Math and Random

26. Useful Built-in Functions

27. Virtual Environments and PIP

28. Database Basics

29. Advanced Practice Programs

30. Mini Projects


1. Introduction to Python
Python is a high-level, general-purpose programming language known for readable syntax. It is used in
web development, automation, data analysis, artificial intelligence, scripting, and many other areas.

Example
print("Hello, World!")

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
2. Variables and Data Types
A variable stores a value. Python determines the type automatically. Common types include int, float, str,
bool, list, tuple, set, and dict.

Example
name = "Mani"
age = 20
height = 5.8
is_student = True

print(name)
print(type(age))

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
3. Input and Output
The input() function reads text from the user. Use int() or float() when numeric input is required.

Example
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Hello", name)
print("Next year:", age + 1)

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
4. Operators
Python supports arithmetic, comparison, logical, assignment, membership, and identity operators.

Example
a = 10
b = 3
print(a + b)
print(a > b)
print(a > 5 and b < 5)

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
5. Strings
Strings are sequences of characters. You can index, slice, search, replace, split, join, and format them.

Example
text = "Python Programming"
print(text[0])
print(text[0:6])
print([Link]())
print([Link]("Python", "Java"))

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
6. Lists
Lists are ordered and mutable collections. They can contain different data types.

Example
numbers = [10, 20, 30]
[Link](40)
numbers[0] = 5
print(numbers)
print(len(numbers))

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
7. Tuples
Tuples are ordered collections that cannot be changed after creation.

Example
point = (10, 20)
print(point[0])
print(len(point))

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
8. Sets
Sets store unique values and support operations such as union, intersection, and difference.

Example
a = {1, 2, 3}
b = {3, 4, 5}
print(a | b)
print(a & b)

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
9. Dictionaries
Dictionaries store data as key-value pairs.

Example
student = {"name": "Arun", "age": 20}
print(student["name"])
student["course"] = "Python"
print(student)

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
10. Conditional Statements
Use if, elif, and else to make decisions.

Example
mark = 75

if mark >= 90:


print("A")
elif mark >= 60:
print("B")
else:
print("C")

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
11. Loops
for loops are useful for iterating over sequences. while loops repeat while a condition is true.

Example
for i in range(1, 6):
print(i)

n = 1
while n <= 5:
print(n)
n += 1

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
12. Functions
Functions group reusable logic. Parameters receive values and return sends a result back.

Example
def add(a, b):
return a + b

result = add(10, 20)


print(result)

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
13. Lambda Functions
A lambda is a small anonymous function.

Example
square = lambda x: x * x
print(square(5))

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
14. Recursion
A recursive function calls itself and must have a base case.

Example
def factorial(n):
if n == 0:
return 1
return n * factorial(n - 1)

print(factorial(5))

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
15. Modules and Packages
A module is a Python file containing reusable code. Packages organize multiple modules.

Example
import math

print([Link](25))
print([Link])

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
16. Exception Handling
Use try, except, else, and finally to handle runtime errors safely.

Example
try:
x = int(input("Enter a number: "))
print(10 / x)
except ValueError:
print("Please enter a valid number.")
except ZeroDivisionError:
print("Cannot divide by zero.")

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
17. File Handling
Python can create, read, write, and append files using open().

Example
with open("[Link]", "w") as file:
[Link]("Learning Python")

with open("[Link]", "r") as file:


print([Link]())

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
18. Object-Oriented Programming
Classes define objects with attributes and methods. __init__ initializes object data.

Example
class Student:
def __init__(self, name):
[Link] = name

def show(self):
print([Link])

s = Student("Arun")
[Link]()

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
19. Inheritance
Inheritance allows a child class to reuse and extend a parent class.

Example
class Animal:
def speak(self):
print("Animal sound")

class Dog(Animal):
def speak(self):
print("Bark")

d = Dog()
[Link]()

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
20. Iterators and Generators
Iterators provide values one at a time. Generators use yield to produce values lazily.

Example
def count_up_to(n):
i = 1
while i <= n:
yield i
i += 1

for x in count_up_to(3):
print(x)

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
21. List Comprehension
Comprehensions provide a concise way to build collections.

Example
squares = [x * x for x in range(1, 6)]
even = [x for x in range(10) if x % 2 == 0]
print(squares)
print(even)

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
22. Regular Expressions
The re module helps search and match text patterns.

Example
import re

text = "My phone is 9876543210"


match = [Link](r"\d{10}", text)
print([Link]() if match else "Not found")

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
23. JSON
JSON is commonly used for exchanging structured data.

Example
import json

data = {"name": "Arun", "age": 20}


text = [Link](data)
print(text)

original = [Link](text)
print(original["name"])

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
24. Dates and Time
The datetime module provides date and time functionality.

Example
from datetime import datetime

now = [Link]()
print(now)
print([Link])

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
25. Math and Random
The math module provides mathematical functions. The random module generates pseudo-random
values.

Example
import math
import random

print([Link](5))
print([Link](1, 10))

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
26. Useful Built-in Functions
Important built-ins include len(), max(), min(), sum(), sorted(), enumerate(), zip(), map(), filter(), and
any()/all().

Example
numbers = [5, 2, 9, 1]
print(len(numbers))
print(max(numbers))
print(sorted(numbers))

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
27. Virtual Environments and PIP
Virtual environments isolate project dependencies. PIP installs third-party packages.

Example
python -m venv venv
pip install requests

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
28. Database Basics
Python applications can work with databases. SQLite is included with Python, while other databases use
dedicated drivers.

Example
import sqlite3

conn = [Link]("[Link]")
cursor = [Link]()
[Link]("CREATE TABLE IF NOT EXISTS students (name TEXT, age INTEGER)")
[Link]("INSERT INTO students VALUES (?, ?)", ("Arun", 20))
[Link]()
[Link]()

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
29. Advanced Practice Programs
Practice problems help develop logic. Start with simple programs and gradually combine conditions, loops,
functions, and data structures.

Example
# Perfect number
n = 28
total = 0

for i in range(1, n):


if n % i == 0:
total += i

print("Perfect" if total == n else "Not Perfect")

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
30. Mini Projects
Good beginner projects include a calculator, number guessing game, quiz app, contact book, expense
tracker, password generator, and student management system.

Example
# Simple calculator
a = float(input("Enter first number: "))
op = input("Enter operator (+ - * /): ")
b = float(input("Enter second number: "))

if op == "+":
print(a + b)
elif op == "-":
print(a - b)
elif op == "*":
print(a * b)
elif op == "/":
print("Cannot divide by zero" if b == 0 else a / b)
else:
print("Invalid operator")

Practice: Rewrite the example using your own values. Then try to modify it to solve a slightly different
problem.
Python Learning Roadmap
• Stage 1 — Fundamentals: syntax, variables, types, operators, strings, collections.

• Stage 2 — Logic: conditions, loops, functions, recursion, comprehensions.

• Stage 3 — Practical Python: modules, packages, exceptions, files, JSON, regular expressions.

• Stage 4 — OOP: classes, objects, inheritance, polymorphism, encapsulation.

• Stage 5 — Real Projects: databases, APIs, automation, data processing, and application development.

• Stage 6 — Interview Preparation: solve problems involving strings, numbers, arrays/lists, dictionaries,
recursion, sorting, and searching.

You might also like