Introduction to Python
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 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/
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 --versionYou should see something like:
Python 3.12.0Step 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.pySet 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
- Go to https://code.visualstudio.com/
- Download the version for your operating system
- 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:
- Open VSCode
- Press
Ctrl+Shift+X(or click the extensions icon in the sidebar) - Search for “Python” and select the one from Microsoft (it has millions of downloads)
- Click Install
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:
- Press
Ctrl+Shift+Pto open the command palette - Type “Python: Select Interpreter” and select it
- 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:
- Create a folder on your computer called
python-course - In VSCode, go to File → Open Folder and select that folder
- Create a new file: File → New File and save it as
hello.py - Write the code from “Your first program” that we saw before
- To run it, click the ▶️ button in the upper right corner, or press
Ctrl+F5
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
Create a program that:
- Asks the user for two numbers
- Shows the sum, subtraction, multiplication, and division of those numbers
Quiz
Test what you’ve learned: