Python Basics

Python Basics

What is a Programming Language

What is a programming language?

A programming language is a set of instructions used to instruct a computer. Languages can be low level, like C, which are close to computer language of 1s and 0s, or higher level languages like Python or JavaScript that are closer to English.

The programmer writes a set of instructions in a programming language and then uses either an interpreter or a compiler to translate the code into machine code that the computer can execute.

An interpreter reads the code line by line and translates it into machine code, which is then handled by a virtual machine to produce the binary instructions the computer can execute.

Diagram showing how an interpreter works

A compiler takes the entire program, reads it and then turns it into machine code all at once.

Diagram showing how a compiler works

Interpreted vs Compiled

Choosing between an interpreted language like Python and a compiled language like C++ usually comes down to a trade-off between development speed and execution performance.

Compiled Languages (e.g. C++, Rust, Go)

In these languages, a program called a compiler translates the entire source code into machine code specifically for the computer's hardware before the program ever runs.

Advantages


Disadvantages


Interpreted Languages (e.g. Python, Ruby, JavaScript)

These languages do not require a pre-run translation. Instead, an interpreter reads and executes the code line by line, translating it on the fly while the program is running.

Advantages


Disadvantages


How to Run Python Code

Navigate to https://www.python.org/ and install the most recent version of Python 3 for your operating system.

Python download page

Check that Python has been properly installed

On Windows, open a terminal by pressing the Windows key and R together, typing cmd and pressing Enter.

On macOS, open a terminal by pressing Command and Space together, typing Terminal and pressing Enter.

Type python --version and press Enter.

Terminal showing python --version command
Terminal showing Python version output

Open or Install VS Code

Navigate to visualstudio.com/download and install the most recent version of Visual Studio Code for your operating system.

VS Code download page

Installing the Python Extension for VS Code

Installing the Python extension in VS Code

Setting Up GitHub and GitHub Desktop

Throughout this course you will save and track your work using GitHub. GitHub is a platform that stores your code online and keeps a history of every change you make. GitHub Desktop is a simple application that lets you manage your code without needing to use the command line.

Step 1: Create a GitHub Account

If you do not already have a GitHub account, go to github.com and sign up for a free account.

Step 2: Install GitHub Desktop

Navigate to desktop.github.com and download GitHub Desktop for your operating system. Once installed, open it and sign in with your GitHub account.

Step 3: Clone the Course Repository

Instead of creating a new repository from scratch, you are going to clone the official Python Essentials repository. Cloning creates a copy of the repository on your computer with all the course folders and starter files already in place.

https://github.com/pythonEssentials2026/pythonessentials.git

Step 4: Open the Repository in VS Code

Once the repository has been cloned, click the button in GitHub Desktop that says Open in Visual Studio Code. You will see all the course folders in the VS Code sidebar, one for each lesson. Your starter files are already there waiting for you.

Installing the Python extension in VS Code

Step 5: Committing and Pushing Your Work

After completing each lesson, save your work and return to GitHub Desktop. You will see your changed files listed on the left. Add a short description in the box at the bottom left, for example completed part3 exercises, then click Commit to main and then Push origin at the top. This saves your work to GitHub and builds a record of your progress.

This course was built by DevSTEM - we turn teaching materials into interactive web courses like this one.

Build your own course