Python from the ground up
Your first programming language
- Beginner
- 15 chapters
- 221 min read
A first course in programming with Python, from your very first line to classes, JSON and tests: every idea comes with a small program you can run in the page, explained in plain words, and a short quiz at the end of each chapter.
What You'll Learn
- Run a Python program and read its output
- Store values in variables and build sentences from them
- Make a program choose with if, elif and else
- Repeat work with loops, and package it in functions
- Keep values in lists and dictionaries
- Read and write files, and handle the errors that happen
- Write a class with its own data and behaviour
- Reach into the standard library with import
- Sort data and build new lists with comprehensions
- Save and load data as JSON
- Work with dates, and count the days between them
- Prove your functions with tests
Prerequisites
- No prior programming experience — the course starts at zero
- Any modern browser; the Python runtime runs in the page
Vocabulary
The terms the chapters assume, in plain words.
- argument
- A value you put inside the parentheses when you call a function, which the function then receives.
- block
- A group of lines that belong together under one opening line, such as the body of an if or a loop.
- branch
- A path a program can take when a condition sends it one way or another.
- call site
- The place in the code where a function is called, as opposed to where it is defined.
- class
- A template that bundles data with the code that works on it; each copy has its own values.
- dictionary
- A collection of key and value pairs, where a key is used to look up its value.
- exception
- An error that stops the normal flow of a program unless some code catches it.
- function
- A named piece of code that does one job and can be called whenever you need it.
- function object
- A function treated as a value, so it can be stored in a variable, passed to another function, or returned.
- indentation
- The spaces at the start of a line that show which block it belongs to.
- integer
- A whole number with no decimal point, such as 3, 0 or -12.
- list
- An ordered collection of values that you can grow, shrink and reach into by position.
- parameter
- A name in a function definition that stands for the value the caller will supply.
- return value
- The result a function hands back to the code that called it.
- scope
- The part of a program where a name can be used; a name made inside a function is not visible outside it.
- traceback
- The report Python prints when a program fails, listing the calls that led to the error.
- variable
- A name that refers to a value, so you can use that value again later or change it.
Course Content
- 01How Python runsNot started
What happens when you press Run: Python reads your file from the top, one line at a time, and the output is what your program says.
- 02Variables and textNot started
Names for values: store a piece of text, change it once, and drop it into a sentence with an f-string.
- 03Making decisionsNot started
if, elif and else: the program asks a question and follows the first answer that is true.
- 04Loops and repetitionNot started
The same line, written once and run many times: for, range and while, and how to keep a loop from running forever.
- 05FunctionsNot started
A name for a piece of work: give it inputs, get an answer back, and stop writing the same lines twice.
- 06Lists and dictionariesNot started
Keeping many values under one name: a list when order matters, a dictionary when you look things up by name.
- 07Reading and writing filesNot started
Notes that outlive the program: open a file, write to it, read it back — and close it the tidy way with with.
- 08When things go wrongNot started
How to read a traceback without panic, the three errors you will meet first, and catching the ones you can answer.
- 09Classes and objectsNot started
A blueprint and the things made from it: your own type with its own data, and the methods that work on it.
- 10Modules and the standard libraryNot started
Other people’s code, one line away: importing from the standard library that ships with Python — math, random and friends.
- 11A small program, end to endNot started
Everything at once: a tiny to-do list that uses a function, a loop, a list and a file — and what to build next.
- 12Sorting and comprehensionsNot started
Putting a list in order, and building a new one from an old one — the two lines that replace a lot of loops.
- 13Working with JSONNot started
The data format of the web, and the one module that turns Python values into it and back again.
- 14Dates and timesNot started
A value for a day: today, thirty days from now, and the two ways to write a date — for people and for machines.
- 15Testing your codeNot started
Writing down what should be true, so a change that breaks it says so — the habit that separates working code from code that worked once.
