Introduction to Python

Module Objectives

By completing this module you will be able to:

  • Understand what Python is and why it’s so popular
  • Install Python on your computer
  • Set up a development environment
  • Write and run your first program

What is Python?

Python is a high-level, interpreted, general-purpose programming language. It was created by Guido van Rossum and its first version was released in 1991.

Main Features

Python Philosophy

Python follows a design philosophy that emphasizes code readability and a syntax that allows expressing concepts in fewer lines than other languages like C++ or Java.

  • Easy to learn: Its syntax is clear and similar to English
  • Versatile: Used in web, data science, AI, automation, games…
  • Large community: Thousands of libraries available
  • Cross-platform: Works on Windows, macOS, and Linux

Where is Python used?

Frameworks like Django and Flask allow creating robust web applications. Instagram, Pinterest, and Spotify use Python in their backends.

Libraries like Pandas, NumPy, and Matplotlib make Python the preferred tool for data analysis and visualization.

TensorFlow, PyTorch, and Scikit-learn are the most popular libraries for artificial intelligence and machine learning.

Python is ideal for automation scripts, from renaming files to web scraping with Selenium or Beautiful Soup.

Installing Python

Step 1: Download Python

Visit the official Python page: https://www.python.org/downloads/

Important

During installation on Windows, check the box “Add Python to PATH”. This will allow you to run Python from any terminal.

Step 2: Verify the installation

Open a terminal (CMD on Windows, Terminal on macOS/Linux) and type:

1python --version

You should see something like:

Python 3.12.0

Step 3: Test the interactive interpreter

Type python in the terminal to open the interactive interpreter:

1>>> print("Hello, Python!")
2Hello, Python!
3>>> 2 + 2
44
5>>> exit()

Your first program

Let’s create a simple program. Create a file called hello.py with the following content:

1# My first Python program
2print("Hello, world!")
3
4name = input("What's your name? ")
5print(f"Nice to meet you, {name}!")

Run it from the terminal:

1python hello.py
  1. # My first program - This is a comment. Python ignores everything after #
  2. print() - Function that displays text on screen
  3. input() - Function that waits for the user to type something
  4. f"..." - F-string, allows including variables inside text

Set up your editor: Visual Studio Code

So far we’ve used the terminal to run Python, and you could write code in Notepad if you wanted. But that would be like trying to cook a banquet with just a knife and a pan: technically possible, but unnecessarily difficult.

Visual Studio Code (VSCode) is a free code editor that will give you superpowers: syntax highlighting, autocomplete, error detection before running, and much more. It’s like going from that basic kitchen to a fully equipped professional kitchen.

Step 1: Install VSCode

  1. Go to https://code.visualstudio.com/
  2. Download the version for your operating system
  3. Install it (next, next, install… you know how it goes)

Step 2: Install the Python extension

VSCode by itself doesn’t know anything about Python. We need to teach it:

  1. Open VSCode
  2. Press Ctrl+Shift+X (or click the extensions icon in the sidebar)
  3. Search for “Python” and select the one from Microsoft (it has millions of downloads)
  4. Click Install
What does this extension include?

The Python extension automatically includes:

  • Pylance: Smart autocomplete that suggests code as you type
  • Python Debugger: To find and fix errors step by step
  • Linting: Warns you of errors before running the code

Step 3: Select the Python interpreter

VSCode needs to know which version of Python to use:

  1. Press Ctrl+Shift+P to open the command palette
  2. Type “Python: Select Interpreter” and select it
  3. Choose the version of Python you installed (you should see something like Python 3.12.x)

Step 4: Create your first project

Let’s organize your workspace:

  1. Create a folder on your computer called python-course
  2. In VSCode, go to File → Open Folder and select that folder
  3. Create a new file: File → New File and save it as hello.py
  4. Write the code from “Your first program” that we saw before
  5. To run it, click the ▶️ button in the upper right corner, or press Ctrl+F5
Your workshop is ready!

VSCode will remember your settings, so you only need to do this once. From now on, simply open the course folder and start coding.

Useful shortcuts

These shortcuts will save you a lot of time:

Shortcut Action
Ctrl+F5 Run the program
F5 Run with debugging (to find errors)
Ctrl+` Open/close the integrated terminal
Ctrl+Space Show autocomplete suggestions
Ctrl+S Save the file

Practical Exercise

Exercise 1: Simple Calculator

Create a program that:

  1. Asks the user for two numbers
  2. Shows the sum, subtraction, multiplication, and division of those numbers
 1# Simple calculator
 2num1 = float(input("Enter the first number: "))
 3num2 = float(input("Enter the second number: "))
 4
 5print(f"Sum: {num1 + num2}")
 6print(f"Subtraction: {num1 - num2}")
 7print(f"Multiplication: {num1 * num2}")
 8
 9if num2 != 0:
10    print(f"Division: {num1 / num2}")
11else:
12    print("Cannot divide by zero")

Quiz

Test what you’ve learned:

🎮 Quiz: Introduction to Python

0 / 0
Loading questions...

Next module

Continue to Fundamentals