Study notes

Python practice guides for beginners.

Practical ways to use the lessons: a core study plan, a method for learning from answers, and focused exercise sets for print, loops, lists, tuples, classes, modules, nested data, recursion, regex, generators, decorators, context managers, dataclasses, itertools, collections, functools, enums, CSV, logging, paths, dates, assertions, type hints, HTTP requests, HTML parsing, URLs, pagination, robots.txt, tokenization, softmax, k-NN, model evaluation, prompt validation, linear regression, gradient descent, Naive Bayes, k-means, and model monitoring.

Start here

Python Practice for Beginners: A Simple 4-Week Plan

Most beginners do not need more videos. They need a small number of concepts, repeated until they can use them without looking. This plan turns the first ten core lessons…

Practice smarter

Python Exercises With Answers: How to Practice Without Copying

An answer is useful only after you have tried the problem. If you read the solution first, you can recognise it later without being able to produce it. This guide shows a…

Lesson focus

Python Print Exercises for Beginners

print() looks simple, but it is the fastest way to inspect a program. These exercises cover the details beginners trip over: separators, line endings, quotes, and formatt…

Lesson focus

Python Loop Exercises: Five Patterns That Cover Most Beginner Problems

Most beginner loop problems are variations of five patterns. Learn to recognise the pattern first, then write the loop. That is faster than starting from a blank line and…

Lesson focus

Python List Exercises for Beginners

Lists are the first data structure most beginners use, and small misunderstandings cause most of the bugs. These exercises focus on indexes, slices, mutation, and the dif…

Focused practice

Python while Loop Exercises: 5 Patterns That Cover Most Problems

Most while-loop exercises are variations on five patterns. Once you can name the pattern, you can write the condition and the update without guessing.…

Focused practice

Python Tuple and Set Exercises: Fixed Records and Unique Values

Tuples and sets solve two different problems: keeping a fixed record, and keeping only unique values. Practice choosing between them instead of defaulting to a list.…

Focused practice

Python List Comprehension Exercises: Map, Filter, and Build

A comprehension is a compact way to build a collection. The useful question is not “Can I shorten this?” but “Does the transformation stay obvious?”…

Focused practice

Python Sorting Exercises: key, reverse, and Record Order

Sorting a list of numbers is only the first step. The useful skill is sorting records by a chosen field while keeping the original data intact.…

Focused practice

Python Class Exercises: Build a Small Object Model

Classes become easier when you start with one small record. Build an object that stores a few fields, add one method, and test it before adding more behaviour.…

Focused practice

Python Import Exercises: Modules, Aliases, and the Standard Library

Imports are a small piece of syntax with a large payoff: they let you use tested code instead of rebuilding every tool. The key is to make the source of each name obvious…

Focused practice

Python Nested Data Exercises: Lists of Dictionaries

Nested data looks complicated until you name each level. A list of dictionaries is just a collection of records; each dictionary is one record with named fields.…

Focused practice

Python Lambda, map, and filter Exercises

map and filter are short tools for transforming and selecting values. They are easiest to use when the function is simple and you remember that both return lazy iterators…

Focused practice

Python Recursion Exercises: Base Cases and Smaller Problems

Recursion is easier when you write the stopping condition first. Then ask one question: what smaller input can this function pass to itself?…

Focused practice

Python Regex Exercises: Search, Find, and Replace

Regular expressions are a compact language for text patterns. Start with one clear pattern, test it on a small string, and only then add groups or quantifiers.…

Focused practice

Python enumerate and zip Exercises: Cleaner Loops

Most loop bugs come from bookkeeping: an index that drifts, a counter that starts at the wrong place, or two lists that silently stop matching. enumerate and zip put thos…

Focused practice

Python pathlib Exercises: Paths, Names, and Text Files

A path is more than a string. It has a parent, a name, a suffix, and a platform-specific separator. pathlib gives those ideas names, so your code can say what it means in…

Focused practice

Python datetime Exercises: Dates, Deltas, and Formatting

Dates look simple until month lengths, leap years, and time zones appear. The datetime module handles the calendar rules for you. The main skill is choosing the right obj…

Focused practice

Python assert Exercises: Testing Functions with Assertions

An assertion is a claim about your program. When the claim is false, Python raises AssertionError and stops the current path. That makes assert a useful teaching and test…

Focused practice

Python Type Hints Exercises: Annotations That Help Readers

Type hints are a communication tool. They tell a reader what a function expects and returns, and they give editors enough information to warn you before a bug reaches run…

Focused practice

Python Generators Practice Guide: Lazy Values

Generators are less about a new syntax trick and more about a different execution model: produce a value, pause, and resume later. That model is useful when a full list w…

Focused practice

Python Decorators Practice Guide: Wrappers

Decorators are a small idea with a large payoff: a function can be passed to another function and replaced by the result. Once that clicks, logging, timing, caching, and …

Focused practice

Python Context Manager Practice Guide

Cleanup is easy to forget on the success path and even easier to miss when an exception interrupts the function. A context manager puts setup and teardown around a block …

Focused practice

Python Dataclass Practice Guide: Fields

A dataclass is a compact way to say that a class is mostly data. It generates the repetitive methods, but it is still a normal Python class. Understanding what it generat…

Focused practice

Python itertools Practice Guide: Lazy Streams

itertools is a toolbox for small iterator operations. The functions do not try to solve a whole problem; they compose. Once you recognize count, islice, chain, and groupb…

Focused practice

Python collections Exercises: Count, Group, and Queue

The collections module is a set of small tools that remove boilerplate. Instead of writing a counting loop, a missing-key check, or a manual queue, you pick a container w…

Focused practice

Python functools Exercises: Cache, Partial, Reduce

functools is about adapting functions without rewriting them. You can cache expensive results, freeze an argument, fold a sequence, or preserve metadata when wrapping a c…

Focused practice

Python Enum Exercises: Names, Values, and Lookup

An enum gives a fixed set of names to a concept such as status, color, or direction. The members are real objects, not loose strings, so comparisons and lookups become ex…

Focused practice

Python CSV Exercises: Read, Write, and Quote

CSV looks like plain text until a comma appears inside a field. The csv module handles quoting, delimiters, and row boundaries so you do not have to split lines by hand.…

Focused practice

Python Logging Exercises: Levels, Handlers, Format

Print statements disappear when you need context. Logging gives each message a severity, a destination, and a format, which makes production behavior easier to inspect wi…

Focused practice

Python Web Scraping Exercises: Build a Polite Pipeline

A scraper is a pipeline, not a single request. These exercises separate fetching, parsing, extracting, and storing so every stage can be tested without hitting a live sit…

Focused practice

Python HTMLParser Exercises: Links, Text, and Attributes

A parser is easier to trust when you build it in small handlers. These exercises add one responsibility at a time: collect tags, read attributes, capture text, then combi…

Focused practice

Python URL Parsing Exercises: Join, Query, and Clean

Most duplicate links are not really duplicates; they are the same destination written four ways. These exercises turn URL strings into components, resolve them against th…

Focused practice

Python Pagination Exercises: Queues, Visits, and Limits

Pagination is a graph walk with a budget. A queue decides what comes next, a visited set prevents loops, and a limit keeps the run finite. These exercises build each piec…

Focused practice

Python robots.txt Exercises: Rules, Delays, and Ethics

robots.txt is a small text file with large consequences. These exercises parse the common directives, explain longest-match precedence, and connect the file to the wider …

Focused practice

Python Tokenization Exercises: Tokens, Vectors, Cosine

Tokenization is the first place where an AI pipeline can quietly lose information. These exercises make the choices visible: what counts as a token, how the vocabulary is…

Focused practice

Python Softmax Exercises: Stability, Temperature, Log Loss

Softmax looks like two lines of arithmetic, but the details matter: overflow, temperature, and the difference between a probability and a decision. These exercises build …

Focused practice

Python k-NN Exercises: Distance, Votes, and Scaling

k-NN is a good first classifier because every decision is visible. You can inspect the distance, the neighbors, the vote, and the evaluation. These exercises make each of…

Focused practice

Python Model Evaluation Exercises: Beyond Accuracy

Evaluation is where a model meets a decision. A single accuracy number can hide a classifier that never finds the class you care about. These exercises compute the confus…

Focused practice

Python Prompt Validation Exercises: JSON, Schemas, Safety

The model is only one part of an AI feature. The surrounding Python decides what goes in, what shape comes out, and what happens when the response is wrong. These exercis…

Focused practice

Python Linear Regression Exercises: Fit, Predict, Evaluate

These exercises keep linear regression small enough to inspect by hand. You will fit a line, measure its error against a baseline, and decide when a prediction is outside…

Focused practice

Python Gradient Descent Exercises: Loss, Steps, Learning Rate

Gradient descent is easier to trust when every step is visible. These exercises isolate the loss, the gradient, the update, and the stopping rule, then show how one bad l…

Focused practice

Python Naive Bayes Exercises: Counts, Priors, Smoothing

A Naive Bayes classifier is mostly careful counting. These exercises build the count tables, turn them into smoothed probabilities, compare classes in log space, and chec…

Focused practice

Python k-Means Exercises: Assign, Update, Measure

k-means becomes less mysterious when assignment, update, and evaluation are separate exercises. These examples use tiny two-dimensional points so every centroid can be ch…

Focused practice

Python Model Monitoring Exercises: Drift and Alerts

Monitoring is a set of small comparisons, not a dashboard full of numbers. These exercises build a baseline, measure a shift, decide whether there is enough evidence to a…

Project walkthrough

Batch AI Jobs in Python: Queue, Retry, Resume, and Cost

A batch job is not a for loop around an API call. This walkthrough builds the four parts that keep a long run honest: stable job keys, a concurrency ceiling, a resume fil…

Project walkthrough

Local LLM Deployment with Python: Ollama, VRAM, and a Real Endpoint

A local model is a process with a memory budget and a latency profile, not a magic box. This walkthrough covers the decisions that decide whether it survives the afternoo…