Skip to content

Introduction to Python

💡
Before you start

You need nothing but the computer in front of you. No account, no payment, no prior programming. This page is the starting point for every other Python tutorial on this site: by the end you will have Python installed, know how to open it, and have run a program you wrote yourself. If you have never opened a terminal before, that is expected — step 1 shows you where it is.

What is Python?

Python is one of the most popular programming languages in the world. Created by Guido van Rossum and first released in 1991, Python is known for its clean, readable syntax that makes it an excellent first language to learn.

Python is used everywhere: web development, data science, artificial intelligence, automation, cybersecurity, and more. Companies like Google, Netflix, Instagram, and NASA all use Python extensively.

💡
Why Python?

Python reads almost like English, has a massive library ecosystem, and has one of the largest developer communities. If you can only learn one language, Python is the best starting point.

Installing Python

Most Linux distributions come with Python pre-installed. Let's check:

python3 --version

You should see something like Python 3.10.12 or higher. If Python is not installed:

Ubuntu / Debian

sudo apt update
sudo apt install python3 python3-pip

Fedora

sudo dnf install python3 python3-pip

Windows

Download the installer from python.org and run it. Make sure to check "Add Python to PATH" during installation.

⚠️
Python 2 vs Python 3

Always use python3 (not python). Python 2 reached end-of-life in 2020 and should not be used for new projects.

The Python Interactive Shell

Python comes with an interactive shell (also called REPL) where you can type code and see results immediately. Start it by typing:

python3

You'll see a prompt like this:

Python 3.10.12 (main, Nov 20 2023, 15:14:05)
[GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

The >>> prompt means Python is waiting for your input.

Your First Python Program

In the Python shell, type the following and press Enter:

>>> print("Hello, World!")
Hello, World!

Congratulations — you just ran your first Python program! The print() function displays text on the screen.

Let's try a few more things:

>>> print(2 + 3)
5
>>> print("Python is " + "awesome")
Python is awesome
>>> print(10 * 5)
50

To exit the interactive shell, type exit() or press Ctrl + D.

Writing a Python Script

While the interactive shell is great for quick experiments, real programs are saved as .py files. Let's create one:

1
Create a new file called hello.py using any text editor:
nano hello.py
2
Type the following code:
# My first Python script
print("Hello, World!")
print("Welcome to Python programming!")

name = "Learner"
print("Hello, " + name + "!")
3
Save and run it:
python3 hello.py

Output:

Hello, World!
Welcome to Python programming!
Hello, Learner!
💡
Comments in Python

Lines starting with # are comments — they're ignored by Python and exist only to explain the code to humans. Use them liberally!

Python's Key Features

  • Readable syntax: Python uses indentation instead of braces, making code naturally clean and consistent.
  • Interpreted language: No compilation step — write code and run it immediately.
  • Dynamically typed: You don't need to declare variable types — Python figures it out.
  • Huge standard library: Batteries included — hundreds of built-in modules for common tasks.
  • Cross-platform: The same Python code runs on Linux, Windows, and macOS.

Now Do It Yourself: Six Steps

This is the part that turns reading into having done it. Work through the six steps on your own machine and you will finish with a working Python and a program you wrote. Every output below is exactly what Python prints.

1
Open a terminal and find out whether you already have Python

Go: open the terminal. Windows: press the Start button, type powershell, press Enter. macOS: press Cmd + Space, type terminal, press Enter. Linux: press Ctrl + Alt + T. A window opens with a blinking cursor; that is all a terminal is — a place to type commands instead of clicking.

Do: type python3 --version and press Enter. If that reports nothing useful, type python --version and press Enter.

You should see: a line such as Python 3.12.3. Any version beginning 3. works for everything on this site. Remember which of the two commands worked — that is the one you will use from now on. On many Linux and macOS machines only python3 exists; on Windows it is usually python.

If not: command not found from both means Python is genuinely not installed — go to step 2. If you see a version starting with 2., that is a retired version from a previous era; install a current one in step 2 and keep using the python3 name.

2
Install Python, only if step 1 found none

Go: if step 1 printed a version, skip this step entirely. Otherwise open python.org/downloads in your browser. Take it from there and nowhere else — Python is a frequent target for lookalike download sites.

Do: the site offers the right installer for your system automatically; download and run it. On Windows there is one setting that matters: on the installer's first screen, tick Add python.exe to PATH before pressing Install. On macOS and Linux there is nothing to choose.

You should see: after it finishes, close the terminal and open a new one, then repeat step 1. It should now print a version.

If not: still command not found on Windows almost always means that tickbox was missed — run the installer again, choose Modify, and enable it. Opening a fresh terminal matters too: a terminal that was already running does not notice a newly installed program.

3
Start Python and make it do something

Go: in the terminal, type python3 on its own (or python, whichever worked in step 1) and press Enter.

Do: at the >>> prompt, type 2 + 2 and press Enter. Then type print("Hello, world!") and press Enter.

You should see: first a banner naming your version, then >>>. After the first line, 4. After the second, Hello, world!. The >>> means Python is waiting for you — this is the interactive shell, and it answers immediately.

If not: if the prompt still shows your normal terminal instead of >>>, Python did not start; recheck step 1. If you typed print("Hello, world!) and nothing happens, you left off a quotation mark — Python is waiting for you to finish the line. Press Ctrl + C and type it again.

4
Leave the shell — the step nobody tells beginners

Go: stay where you are, at the >>> prompt.

Do: type exit(), with the two brackets, and press Enter.

You should see: the >>> disappears and your ordinary terminal prompt returns. You are out of Python and back in the terminal.

If not: typing exit without the brackets gets you Use exit() or Ctrl-D (i.e. EOF) to exit — Python telling you politely. This trips up almost everyone once. Knowing where you are matters: >>> means Python is listening and expects Python; anything else means the terminal is listening and expects commands like python3.

5
Write a program in a file and run it

Go: open a plain text editor. Windows: Notepad, from the Start menu. macOS: TextEdit, then choose Format → Make Plain Text. Linux: Text Editor / gedit. Any of these is fine for now; a programmer's editor comes later and changes nothing here.

Do: type these two lines, then save the file as hello.py in your home folder. In Notepad's Save dialog, set "Save as type" to "All Files" first, and in TextEdit untick "If no extension is provided, use .txt". Then in the terminal run cd ~ followed by python3 hello.py.

print("Hello, world!")
print("Python is working.")

You should see: two lines, Hello, world! and Python is working. You have just written and run a program.

If not: python3: can't open file '...hello.py': [Errno 2] No such file or directory has two causes and the message tells you which. If the path shown is not where you saved the file, the terminal is in the wrong folder — cd ~ moves to your home folder. If the path is right, your editor almost certainly saved hello.py.txt: that is the dialog setting above, and it is the single most common first-day obstacle. Turn on file extensions in your file manager so you can see the real name.

6
Cause an error on purpose, so errors stop being frightening

Go: open hello.py again in the same editor.

Do: delete the closing bracket from the first line so it reads print("Hello, world!", save, and run python3 hello.py again.

You should see: a SyntaxError naming the file and the line number. Read the line number first, every time — Python is telling you exactly where to look. Put the bracket back, save, run it again, and the two lines return.

If not: if it still prints normally, the file did not save; check the title bar of your editor for a dot or the word "edited". An error message is not a failure and never breaks anything — it is Python's only way of saying which character confused it. You will read thousands of them.

🎉
Check yourself before moving on

Without scrolling up: you are looking at >>> and you want to run hello.py. What must you do first, and why? Answer: type exit() to leave Python. >>> means Python is listening and expects Python code; python3 hello.py is a command for the terminal, not for Python.

Now do it without the page: make a second file called about.py that prints your name and your favourite number on two separate lines, and run it. Same five moves as step 5, different content — if you can do that unaided, you are ready for variables.

Summary

In this tutorial, you learned:

  • What Python is and why it's worth learning
  • How to install Python and verify your installation
  • How to use the Python interactive shell
  • How to write and run your first Python script
  • Python's key features that make it beginner-friendly
🎉
Great start!

You've written your first Python code! In the next tutorial, you'll learn about variables and data types — the building blocks of every Python program.