Free course · 50 topics · about 60 hours
Python Programming
0/50 topics done
Beginner
Your first programs: printing, numbers, text, decisions, loops and collections.
1First steps in Python0/4 topics▼
What programming is, why Python is popular, and your first programs: printing, comments, variables and numbers.
- What programming and Python areProgramming means writing exact steps for a computer to follow. Python is a programming language with simple, English-like words, so it is one of the easiest languages to start with. It is also used for real jobs: websites, data analysis, automation and AI.15 min
- print() and commentsprint() shows values on the screen. You can print text, numbers, or several things at once separated by commas. A comment starts with # and is a note for humans; Python ignores it.15 min
- Variables: giving names to valuesA variable is a name that points to a value, like price = 120. You create it with the = sign and use the name later instead of the value. You can change it at any time, and good names make your code easy to read.20 min
- Numbers and mathsPython does maths with + - * / and a few extra operators: // for whole-number division, % for the remainder and ** for powers. Whole numbers are int, decimals are float, and round() tidies long decimals.20 min
2Text and decisions0/4 topics▼
Work with text (strings, f-strings and string methods), compare values with True and False, and let your program choose what to do with if, elif and else.
- Strings: working with textA string is text inside quotes, like "Mumbai". You can measure it with len(), join strings with + and repeat them with *. Each character has a position number starting at 0, so you can pick one character or cut out a slice.20 min
- f-strings and string methodsAn f-string is a string with f before the quotes, where anything inside curly brackets {} is filled in with its value. String methods like upper(), strip(), replace() and split() give you a changed copy of the text. They never change the original string.25 min
- Booleans and comparisonsA boolean is a value that is either True or False. Comparisons like age >= 18 or name == "Ravi" give a boolean. You can combine them with and, or and not, and every value in Python also counts as either true-like or false-like.20 min
- if, elif and elseAn if statement runs some lines only when a condition is True. else gives a second path for when it is False, and elif lets you check several conditions one after another. The lines inside each part must be indented by 4 spaces.25 min
3Loops: repeating work0/4 topics▼
Make Python repeat work for you: for loops with range(), while loops, break and continue, and the common loop patterns behind totals, counts, maximums and tables.
- for loops and range()A for loop repeats a block of code once for each item: each character of a string, or each number from range(). range(5) gives 0, 1, 2, 3, 4, and range(start, stop, step) lets you choose where to start, where to stop and how big each jump is. The stop number itself is never included.25 min
- while loopsA while loop repeats its block as long as a condition stays True. Python checks the condition before every round. Something inside the loop must change, or the condition stays True forever and the loop never stops.20 min
- break, continue and loop elsebreak stops a loop at once, and continue skips the rest of the current round and moves to the next one. A loop can also have an else block, which runs only when the loop finished without a break. pass is a placeholder that does nothing.20 min
- Common loop patternsMost loops follow a few patterns: keep a running total, count matching items, remember the biggest or smallest value, or build a new string piece by piece. They all use an accumulator, a variable set up before the loop and updated in every round. Loops can also sit inside other loops to make tables and patterns.25 min
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.
- 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
- 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
- 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
- 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
- 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
Intermediate
Functions, errors, the standard library, working with data and real projects.
1Functions0/4 topics▼
Write your own functions: define and call them, pass inputs with parameters and defaults, accept any number of arguments with *args and **kwargs, and understand where variables live (scope).
- Defining and calling functionsA function is a named block of code that does one job. You define it with def, and you run it by calling its name with brackets. return hands a value back to the code that called it; a function without return gives back None.20 min
- Parameters, arguments and defaultsParameters are the names in the def line; arguments are the values you pass when you call. You can pass arguments by position or by name (keyword arguments), and give parameters default values. Never use a list as a default value: it is shared by every call.20 min
- *args and **kwargs*args lets a function accept any number of positional arguments, which arrive as a tuple. **kwargs collects any number of keyword arguments into a dict. When calling, * and ** do the opposite and spread a list or dict into separate arguments. Parameters after * can only be passed by name.20 min
- Scope: where variables liveA variable made inside a function is local: it exists only inside that function. A variable made at the top of the file is global and can be read everywhere. Python looks up names in the order Local, Enclosing, Global, Built-in. The global and nonlocal keywords let a function change an outer variable, and lambda makes small one-line functions.25 min
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.
- 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
- 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
- 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
- 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
- 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
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.
- 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
- 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
- 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
- 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
- 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
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.
- 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
- 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
- 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
- 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
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.
- 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
- 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
- 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
- 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
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.
- 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
- 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
- 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
- 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
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.
- 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
- 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
- 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
- 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
4Python in the real world0/3 topics▼
Install packages safely with virtual environments and pip, see how Python is used for web, data and AI, and prepare for Python interviews.
- Virtual environments and pipA package is ready-made code that someone else wrote and shared. pip downloads packages from PyPI, the Python Package Index. A virtual environment is a private folder of packages for one project, so two projects never fight over versions.25 min
- What Python is used for: web, data and AIPython is used to build websites and APIs (Django, FastAPI), to analyse data (pandas), to build AI and machine learning systems, and to automate boring tasks. These tools are packages built on the same basics you already know: functions, dicts, lists and classes.25 min
- Python interview preparationPython interviews usually have an online test, a coding round, a technical discussion and an HR round. Practise classic problems (palindromes, FizzBuzz, two-sum), learn short clear answers to common theory questions, and always explain your thinking out loud.30 min
🎓 Final exam and certificate
30 questions, 60 minutes, pass mark 60%. Pass it to get a certificate with your name.