EMFAD Courses

Module 1: Python Foundations

Installing Python and Your First Program

Before you can write a single useful program, you need a working Python installation and a comfortable place to type code. Many beginners lose days fighting with setup, so this lesson walks you through it carefully. By the end you will have Python installed, a code editor ready, and your first program running on your own computer.

What Python is and why it is worth learning

Python is a general purpose programming language. It is used for automating office tasks, building websites, analysing data, writing scripts that talk to other systems, and much more. Its syntax is designed to be readable, which makes it a good first language. The skills you build here (thinking in steps, breaking problems down, reading error messages) carry over to every other language you learn later.

Python code is run by a program called the interpreter. When you "run a Python file", the interpreter reads your code line by line from top to bottom and carries out each instruction. So installing Python really means installing the interpreter.

Installing Python step by step

Always download Python from the official site, python.org. Choose the latest stable Python 3 release. Python 2 reached its end of life years ago and you should not use it for new work.

  1. Windows: download the installer from python.org/downloads. On the first screen of the installer, tick the box labelled Add python.exe to PATH before clicking Install Now. This lets you run Python from any terminal window.
  2. macOS: download the macOS installer from python.org and run it. On a Mac you normally type python3 rather than python.
  3. Linux: most distributions already include Python 3. Check with python3 --version and use your package manager if it is missing.

To confirm the installation, open a terminal (Command Prompt or PowerShell on Windows, Terminal on macOS and Linux) and type:

python --version
# or, on macOS and Linux
python3 --version

You should see something like Python 3.13.1. The exact number does not matter as long as it starts with 3 and is a recent release.

Choosing an editor

You can write Python in any plain text editor, but a code editor makes life much easier. A popular free choice is Visual Studio Code with the official Python extension installed. It gives you colour highlighting, warnings about mistakes, and a built in terminal. Python also ships with a simple editor called IDLE, which is fine if you want to start immediately.

Create a folder for this course, for example python-course in your Documents folder. Keep every exercise file in it. A tidy folder saves you time when you want to find old work.

Your first program

There are two ways to run Python code. The first is the interactive shell (also called the REPL). Type python (or python3) in the terminal and you will see a >>> prompt. Type an instruction, press Enter, and Python answers immediately:

>>> print("Hello, Nairobi!")
Hello, Nairobi!
>>> 2 + 3
5
>>> exit()

The shell is great for quick experiments, but anything you type there is lost when you close it. Real programs live in script files ending in .py. Create a file called hello.py in your course folder with this content:

# hello.py - my first Python program
print("Hello, world!")
print("My name is Amina and I am learning Python.")
print("Today I will write my first script.")

Save the file, open a terminal in the same folder, and run:

python hello.py

Python runs each print line in order and shows three lines of output. The line starting with # is a comment. Python ignores comments; they are notes for humans reading the code.

A few things to notice about print("Hello, world!"): print is a built in function, the round brackets hold what you give it, and the text inside quotes is called a string. You will learn more about each of these in the coming lessons.

Common mistakes to avoid

  • Forgetting to tick "Add to PATH" on Windows. If typing python says the command is not recognised, rerun the installer, choose Modify, and enable the PATH option, or use the py launcher instead.
  • Running a file from the wrong folder. If you see "No such file or directory", your terminal is in a different folder from your script. Use cd to move into the right folder first.
  • Typing shell prompts into files. The >>> symbols belong to the interactive shell. Never paste them into a .py file.
  • Mismatched quotes or brackets. print("Hello) causes a SyntaxError. Every opening quote and bracket needs a matching closing one.
  • Capital letters. Python is case sensitive. Print is not the same as print, and will fail with a NameError.

Error messages are not a sign of failure; they are Python telling you exactly what went wrong and on which line. Read the last line of any error first, then look at the line number it mentions. Getting comfortable with errors now will make everything that follows easier.

Exercise

Install Python from python.org and confirm it with python --version (or python3 --version). Create a folder called python-course and inside it a file called about_me.py. Make the program print five lines: your name, your town, what you do for work, why you are learning Python, and one thing you want to automate. Run it from the terminal and fix any errors until all five lines appear.

Key points

  • Install Python 3 from python.org and confirm it with python --version.
  • The interactive shell is for quick experiments; .py files hold programs you keep.
  • Run a script with python filename.py from the folder that contains it.
  • Read the last line of an error message first, then check the line number.

Enjoyed this lesson?

The full course has 16 lessons with exercises, a quiz after every module, a final project and a certificate of completion. About 7 hours, USD 49, lifetime access.

Course details