Skip to content

Free course · 50 topics · about 60 hours

Python Programming

From your first print() to classes, algorithms and tests, in your browser.

0/50 topics done

Start the course →

Beginner

Your first programs: printing, numbers, text, decisions, loops and collections.

1First steps in Python0/4 topics▼
2Text and decisions0/4 topics▼
3Loops: repeating work0/4 topics▼
4Lists, tuples, dictionaries and sets0/5 topics▼

Store many values under one name: lists you can change, tuples that stay fixed, dictionaries that look things up by name, and sets that keep each item only once.

  1. Lists: many values in one nameA list holds many values in order inside square brackets, like marks = [78, 91, 65]. Each item has a position number called an index, and Python starts counting at 0. You can change items, loop over them, check membership with in, and use len, sum, min and max.20 min
  2. List methods and slicingLists have methods that change them: append, insert, extend, remove, pop, sort and reverse. Slicing like marks[1:3] takes a part of a list as a new list. Be careful: b = a does not copy a list, it gives the same list a second name; use a.copy() for a real copy.25 min
  3. Tuples: fixed groups of valuesA tuple is like a list that cannot be changed after it is made. You write it with round brackets, like ("Asha", 88). Tuples are good for small fixed records, and you can unpack them into separate variables in one line. A one-item tuple needs a comma: (5,).15 min
  4. Dictionaries: look things up by nameA dictionary (dict) stores key-value pairs, like {"chai": 15, "samosa": 20}. You look up a value by its key instead of by a position number. get() gives a default when a key is missing, and items() lets you loop over keys and values together.25 min
  5. Sets: each item only onceA set is a collection where each item appears only once, like {"Pune", "Delhi"}. Sets are the easiest way to remove duplicates and to check membership quickly. You can combine two sets with union, intersection and difference. Note that {} makes an empty dict, so an empty set is set().15 min
📝 Module exam · 12 questions · 25 min

Intermediate

Functions, errors, the standard library, working with data and real projects.

1Functions0/4 topics▼
2Errors, modules and the standard library0/5 topics▼

Handle errors calmly with try and except, import modules, and use the ready-made tools that come with Python: math, random, datetime, collections, itertools, json and regular expressions.

  1. Errors and exceptionsWhen something goes wrong while a program runs, Python raises an exception and prints a traceback: the error type, a message and the line where it happened. With try and except you catch a specific error and handle it instead of crashing. With raise you report your own errors with a clear message.20 min
  2. Modules and importsA module is a Python file full of ready-made functions. You load it with import. Python comes with a large standard library, such as math for maths and random for random choices, and any .py file you write is a module too.20 min
  3. Dates and times with datetimeThe datetime module handles dates and times: date for a calendar day, datetime for a day plus a clock time, and timedelta for a gap such as 30 days. strftime turns a date into text like "15-08-2024", and strptime reads such text back into a date. Subtracting two dates tells you how many days lie between them.20 min
  4. collections and itertoolsThe collections module gives you smarter containers: Counter counts things, defaultdict fills in missing keys, namedtuple gives a tuple named fields, and deque is a fast queue. The itertools module has ready-made loop tools: chain, count, combinations, permutations, product and groupby. They replace many long hand-written loops.25 min
  5. JSON and regular expressionsJSON is the text format apps and websites use to send data. The json module turns Python dicts and lists into JSON text with dumps, and back again with loads. Regular expressions are small search patterns, like "ten digits starting with 6 to 9" for an Indian mobile number, and the re module uses them to search, find and replace text.25 min
📝 Module exam · 14 questions · 25 min
3Working with data0/5 topics▼

Turn raw data into answers: build lists and dicts with comprehensions, clean messy text, sort by any rule, read and write files, and summarise CSV tables with the statistics module.

  1. List, dict and set comprehensionsA comprehension builds a new list, dict or set in one line from another collection, like [p * 2 for p in prices]. Add an if at the end to keep only some items. Comprehensions are short and fast, but when the logic grows long, a plain for loop is easier to read.20 min
  2. String processingReal text is messy: extra spaces, mixed capital letters and stray symbols. String methods such as strip, lower, replace and split clean it up, and isdigit or isalpha check what a piece of text contains. With join, zfill and ljust you can then build neat reports.20 min
  3. Sorting with keysorted() gives you a new sorted list, while list.sort() sorts the list itself and returns None. The key argument tells Python what to compare, such as key=len or key=lambda s: s[1]. Add reverse=True for biggest first, and use a tuple as the key to sort by two things at once.20 min
  4. Working with filesopen() connects your program to a file so you can read it or write to it. Mode "r" reads, "w" writes a fresh file and "a" adds to the end. Always use with open(...) as f: so the file is closed for you, and pass encoding="utf-8" so Hindi and other scripts work.20 min
  5. CSV files and simple statisticsCSV (comma-separated values) is the simple table format that Excel and Google Sheets can save and open. The csv module reads it row by row and correctly handles commas inside quoted values. The statistics module then gives you the mean, median, mode and standard deviation in one line each.25 min
📝 Module exam · 13 questions · 25 min
4Projects: put it all together0/4 topics▼

Four small projects that use everything you have learned: a marks and grade calculator, an expense tracker, a quiz game with negative marking and a password strength checker. Each one is planned, built as small functions and tested.

  1. Project: marks and grade calculatorYou will build a report card calculator for a class: total marks, percentage, grade, pass or fail, the class topper and the class average. The project is split into small functions, and each one is tested before the next one is written. This is how real programmers build bigger programs.30 min
  2. Project: expense trackerYou will build the logic of an expense tracker: add an expense safely, total by category, total for a month, find the biggest expense and warn when the budget is nearly used. At the end you will split a trip bill among friends and work out who owes whom.35 min
  3. Project: quiz game with negative markingYou will build the logic of a quiz game like a mock test for a competitive exam: questions stored as data, answers checked fairly, +4 for right, -1 for wrong and 0 for skipped. You will also make a result summary and shuffle questions with a seed so the order can be repeated.30 min
  4. Project: password strength checkerYou will build a password strength checker like the one you see on sign-up forms. It checks length, capital letters, small letters, digits and symbols, gives a score and a label (weak, medium or strong) and lists what is missing. You will also learn why real sites never store passwords as plain text.30 min
📝 Module exam · 12 questions · 25 min

Expert

Object-oriented design, advanced Python, algorithms, testing and Python at work.

1Object-oriented programming0/4 topics▼

Bundle data and the functions that work on it into classes. Learn objects, __init__ and self, inheritance, magic (dunder) methods that let your objects work with print, ==, sorted, + and in, and dataclasses that write the boring parts for you.

  1. Classes and objectsA class is a blueprint that describes what data a thing has and what it can do. An object (also called an instance) is one real thing made from that blueprint. __init__ sets up each new object, and self means "this particular object".30 min
  2. Inheritance and compositionInheritance lets a new class (the child) reuse and extend an existing class (the parent). The child gets all the parent's methods and can override some of them. Composition is the other way to reuse code: an object holds other objects. Use inheritance for "is a" and composition for "has a".30 min
  3. Dunder (magic) methodsDunder methods have names with double underscores on both sides, like __str__ and __add__. Python calls them for you behind the scenes: print() calls __str__, == calls __eq__, < calls __lt__, + calls __add__, len() calls __len__ and in calls __contains__. Writing them makes your own objects work like built-in ones.30 min
  4. Dataclasses and propertiesA dataclass is a class mostly used to hold data. Put @dataclass above it and list the fields with types; Python writes __init__, __repr__ and __eq__ for you. You can add defaults, make objects unchangeable with frozen=True, sortable with order=True, and use @property for computed values and validation.30 min
📝 Module exam · 13 questions · 30 min
2Advanced Python0/4 topics▼

The tools experienced Python programmers use every day: iterators and generators for working with big data lazily, decorators for adding behaviour to functions, context managers for safe clean-up, and type hints for clearer code.

  1. Iterators and generatorsAn iterable is anything you can loop over; an iterator is the object that hands out its items one at a time and remembers where it is. A generator is a function that uses yield to produce values one by one, only when they are asked for. This "lazy" style saves memory, so you can work with millions of items or even endless streams.30 min
  2. DecoratorsA decorator is a function that takes another function and returns a new function with extra behaviour, such as timing, logging, caching or a login check. You apply it by writing @decorator_name on the line above a def. Decorators work because Python functions are objects that you can pass around and return.35 min
  3. Context managers and the with statementA context manager sets something up when a with block starts and always cleans it up when the block ends, even if an error happens inside. Files, locks and database connections use it so nothing is left open. You can write your own with __enter__ and __exit__, or more simply with contextlib.contextmanager and one yield.30 min
  4. Type hintsType hints are notes in your code that say what type a variable, parameter or return value should be, like def total(prices: list[float]) -> float. Python itself does not check them when the program runs. Tools such as mypy and pyright, and your code editor, read them to catch mistakes before you run anything.30 min
📝 Module exam · 13 questions · 25 min
3Algorithms, data structures and testing0/4 topics▼

Prove your code works with tests, measure how fast an algorithm grows with Big-O, search and sort data efficiently, think recursively, and use stacks, queues and priority queues. These ideas come up in every coding interview.

  1. Testing your codeA test is a small piece of code that runs your code with known inputs and checks the answer. Tests catch mistakes early and tell you at once if a later change breaks something that used to work. Python has assert, the built-in unittest module, and the popular pytest tool for writing and running tests.30 min
  2. Big-O and searchingBig-O is a simple way to describe how much more work an algorithm does as the data grows: O(1) stays the same, O(n) grows in step with the data, O(log n) grows very slowly and O(n^2) explodes. Linear search checks items one by one; binary search halves a sorted list each step. Sets and dicts find items almost instantly because they use hashing.30 min
  3. Recursion and sorting algorithmsRecursion means a function calls itself on a smaller piece of the problem until it reaches a case simple enough to answer directly, called the base case. Sorting algorithms put items in order: simple ones like selection sort take O(n^2) steps, while merge sort uses recursion to sort in O(n log n). In real work you use Python's built-in sorted(), which is fast, stable and well tested.35 min
  4. Stacks and queuesA stack is a pile where the last item added is the first one taken out (LIFO); a Python list with append() and pop() works as a stack. A queue is a line where the first item added is the first one out (FIFO); use collections.deque for it. For "most urgent first", the heapq module gives you a priority queue.30 min
📝 Module exam · 13 questions · 30 min
4Python in the real world0/3 topics▼

🎓 Final exam and certificate

30 questions, 60 minutes, pass mark 60%. Pass it to get a certificate with your name.