Toolpuffin

    Loading...

    Up and down to choose, Enter to open, Esc to close.

    How to Learn Python for Beginners: A Simple Plan

    Updated December 2026

    Written by the Toolpuffin team. Tools in this guide are tested in the browser.

    Python is a programming language that is used for scripts, data work and much more. This guide gives a simple order to learn the basics, explains the rule about indentation that surprises many beginners, shows how to run Python on your own computer and links to a free course to practise with. The facts come from the official Python documentation.

    Try the tool: Learn Python

    Where Python comes from

    The Python interpreter and its standard library are freely available for all major platforms from python.org. The official tutorial is written for people who are new to Python, not for people who are new to programming, so do not worry if some parts feel quick at first: the order below starts smaller.

    What to learn first

    1. Print a line of text with print(). Text goes between quotes, and either single or double quotes give the same result.
    2. Store values in variables and write comments with #. A comment runs to the end of the line.
    3. Calculate with numbers. The / sign always gives a decimal number, // gives a whole number (floor division) and % gives the remainder.
    4. Make choices with if, elif and else. The elif part is short for else if and the else part is optional.
    5. Repeat things with for. A for loop goes over the items of a list or a string, and range() gives you a sequence of numbers.
    6. Group code in functions with def and give back a value with return. A function without a return gives back None.
    7. Keep several values in a list and add to it with append().
    8. Look things up by name in a dictionary, a set of key: value pairs where every key is unique.

    Each step uses the one before it, so a short session on one step a day works better than reading everything at once.

    Indentation is part of the code

    Python uses the spaces at the start of a line to see which lines belong together. The body of a function starts on the next line and must be indented, and the same goes for the lines inside an if or a loop. PEP 8, the style guide for Python code, says to use 4 spaces per indentation level and calls spaces the preferred method. Python 3 does not allow mixing tabs and spaces for indentation, so pick spaces and keep to them.

    How to run Python yourself

    Install Python from python.org, save your code in a file that ends in .py and give that file name to the interpreter, for example python myscript.py. On Linux and macOS the command can be python3, because the Python documentation says Unix builds do not install a plain python command by default. On Windows the py launcher can be used. Typing only the command starts interactive mode, where the prompt is >>> and you leave with quit().

    A course in a web page cannot run Python for you the way your own computer can. The free course below checks that your answer contains what the task asks for and shows what the program would print, so also run your code yourself to see real results and real error messages.

    Common mistakes

    • Forgetting the colon at the end of an if, for or def line.
    • Wrong indentation: lines that belong together must start with the same number of spaces.
    • Mixing tabs and spaces in one file, which Python 3 does not allow.
    • Expecting range(5) to include 5. The end point is never part of the sequence, so range(5) gives 0 to 4.
    • Asking a dictionary for a key that is not there. Square brackets raise a KeyError, while .get() gives None instead.
    • Thinking a # inside quotes starts a comment. Inside a string it is just a character.

    What to learn next

    After the basics, the tutorial continues with modules, reading and writing files, errors and classes. If you also want to see how another language looks, there are free courses for JavaScript and PHP.

    Sources

    More guides