Intro to Python
Your first real programs, from one line that prints a number to a small tool that reads a file, with an animated diagram in every lesson showing what the code actually does.
For absolute beginners who have never written a line of code. You learn Python one idea at a time: values and variables, text, input, decisions, lists, loops, functions, dictionaries, error messages and files. Every lesson has short, real code examples with the output they print, and an animated diagram you step through that shows what happens inside: variables as labelled boxes, a loop stepping along a list, a function call stacking up and returning. The last lesson puts it all together in a small expense tracker that reads a file and prints a report.
By the end you can
- Read a short Python program line by line and say what it prints before you run it
- Store and change data with variables, strings, lists and dictionaries
- Control a program with if, for and while, and package steps into your own functions
- Read an error message to find the broken line, and build a small program that reads a file and reports on it
First steps
- Your first program
A program is a list of instructions Python runs from top to bottom. Write your first lines with print, and use Python as a calculator that knows the order of operations.
- Variables: names for values
A variable is a name that points at a value so you can use it later. Learn how = stores a value, how to change it, and why changing one variable doesn't quietly update another.
- Strings: working with text
Text in Python is a string, a row of characters in quotes. Join strings, measure them, pick out characters by position, and build sentences with f-strings.
Input, decisions and lists
- Input and types
input() lets your program ask a question, but the answer always comes back as text. Learn the main types and how to convert between them, so "7" + "3" stops giving you 73.
- Making decisions with if
Comparisons give True or False, and if, elif and else use them to choose which lines run. Learn why indentation matters and why the order of your tests changes the answer.
- Lists: many values in one place
A list keeps values in order under one name. Get items by position, add and change them, and learn the error you get when you ask for a position that isn't there.
Repeat, reuse, look up
- Loops: doing it again
A for loop runs the same lines once for every item in a list or a range. Add things up with a running total, count with range, and use while when you don't know how many times in advance.
- Functions: name a job, reuse it
A function packages steps under a name so you can run them whenever you need. Pass in values as parameters, send a result back with return, and see what happens on the call stack when one function calls another.
- Dictionaries: look it up by name
A dictionary stores pairs of key and value, so you find things by a name instead of a position. Add and update entries, loop over them, and avoid the KeyError with get.
Real programs
- Reading error messages
An error message is Python telling you where it stopped and why. Read a traceback from the bottom up, recognise the six errors beginners meet most, and catch one you expect with try and except.
- Saving and reading files
Variables disappear when the program ends; files stay. Open a file with with, write lines to it, add to it without wiping it, and read it back line by line.
- Final project: an expense tracker
Put the whole course together in one small program: read your expenses from a file, add them up by category in a dictionary, and print a report, built one working step at a time.
Keep it, don't just read it
Pathwise brings each idea back just before you'd forget it, with a quick question. Free on Android and on the web, in English and Persian.