Python Basics

Python is one of the most popular programming languages in the world, and one of the easiest to read. In these lessons you write real Python, run it right here in the page, and get each exercise checked as you go.

0 of 12 lessons done
Start Course

Part 1First Steps

  1. Hello, PythonRun your first Python program, print text and numbers, and write comments.
  2. VariablesStore values under a name, change them later and choose good variable names.
  3. Numbers and MathCalculate with whole numbers and decimals, and learn Python's division, remainder and power operators.
  4. StringsJoin text, insert values with f-strings and use string methods like upper, replace and len.
  5. Asking for InputMake programs interactive with input(), and convert text to numbers with int() and float().

Part 2Controlling the Flow

  1. Making DecisionsRun different code depending on a condition with if, elif and else, and learn why indentation matters.
  2. For LoopsRepeat code a set number of times with for and range(), and build up a running total.
  3. While LoopsRepeat code while a condition is true, stop early with break and avoid loops that never end.

Part 3Working With Data

  1. ListsStore many values in a list, read items by index, add and remove items and loop over them.
  2. FunctionsWrite your own functions with def, pass in arguments and return results.
  3. DictionariesLook values up by name with dictionaries: create them, read, add and change entries, and loop over them.
  4. Project: A Score ReportCombine lists, dictionaries, loops and functions to write a program that analyzes quiz scores.

Your Certificate

Finish every lesson in this course to unlock a certificate with your name on it.

What you will learn

Python is used for data analysis, automation, web servers, science and teaching. Its clean style makes it a favorite first language. This course takes you from printing a line of text to writing a small program that analyzes data.

Real Python, nothing to install

The lessons run genuine Python 3 inside your browser. The first time you run a Python lesson, the page downloads the Python engine (about 5 MB), which can take a few seconds. After that your browser keeps a copy and it starts quickly.

How the lessons work

Type your program and press Run to see its output. Error messages show which line went wrong, and that line is highlighted. Check My Code runs your program and tests the result. For programs that ask for input, the answers come from the Input box under the editor.

Frequently asked questions

Is this Python course free?

Yes. Every lesson is free, with no account and no limits.

Do I need to install Python?

No. Python runs inside the page. The first run downloads the engine, about 5 MB, and after that it is kept by your browser.

Which version of Python is it?

Python 3.12, running through the open-source Pyodide project. What you learn applies to Python on any computer.

Why is the first run slow?

The Python engine has to download and start. That takes a few seconds once. Later runs, and later visits, are fast.

Can my Python code reach the internet or my files?

No. It runs in a sandbox inside your browser with no access to the network, your files or the rest of this site.

Do I get a certificate?

Yes. Finish every lesson to unlock a certificate of completion with your name on it. It is a personal record, not an accredited qualification.