Introduction to Python, the interpreter and coding style

Welcome to our nine-part walkthrough of The Python Tutorial!

This is the official guide for Python, produced and maintained by the developer community. For those interested, the tutorial materials themselves live on Github. You can tell it’s official because

NoteThird-party tutorials

When you search “Python tutorial” online, there’s a lot of results. Some are decent educational materials, others are pretty poor quality and some are AI generated. Only The Python Tutorial is the official one!

You might be concerned by the banner at the top of the page, which reads

Tip

Tip: This tutorial is designed for programmers that are new to the Python language, not beginners who are new to programming.

Certainly, this tutorial is not a beginner’s guide to programming. This can make it challenging for newcomers. However, it’s a great, succinct overview of the language, with all the important features covered. So, don’t stress - we’ll just walk you through the important bits.

Structure of this series

We’re only going to spend 20 minutes each month on each section. That’s not a lot of time. This means that,

  • We’re only going to demonstrate key concepts/features
  • You should have a play on your own

That said, we will cover some important things, and hopefully by November, you’ll have a good, comprehensive handle on how Python actually works.

Here’s a summary of what we’re planning to cover:

Month Overview Section
March Introduction to Python, the interpreter and coding style. 1-3 and 4.10
April Control flow tools Conditionals (if, else, elif) Loops (for and while, break and continue) Match-case 4.1-4.7
May Functions Defining vs calling Default vs keyword vs positional arguments 4.8-4.9
June Data Structures Lists, tuples, sets, dicts Fancy looping And how pandas DataFrames fit into all this 5
July Modules How and where to write them How to import them And how PyPI fits into this 6
August Input and Output Format strings Reading and writing files 7
September Errors and Exceptions Syntax vs everything else Handling and raising them 8
October Classes What are they—do I need them? How to write them Attributes vs variables, methods vs functions Who is self? Am I object-oriented? This is a complex topic. We’ll only scratch the surface, but it’ll help explain a lot of Python behaviour. 9
November Brief Tour of the Standard Library Modules like os, glob, sys, math, datetime, urllib 10
December Something fun :)

1. Whetting Your Appetite

Why Python?

The first section of the tutorial gives us a bit of motivation. Let’s compare with some other popular languages.

As of Feb 2026, the TIOBE index puts Python in pole position:

Top 50%:

  1. Python (22%)
  2. C (11%)
  3. C++ (9%)
  4. Java (8%)
  5. C# (7%)

Bottom 50%:

  1. JavaScript (3%)
  2. Visual Basic (3%)
  3. R (2%)

What are some uses/features of these other languages?

  • C/C++/C#/Java (35%): Software development. Need to write/compile/test/recompile every time. Big, heavy, complex languages. Python itself is written in them.
  • JavaScript (3%): Websites. Good for running code on web servers, but less support for code beyond this.
  • Visual Basic (3%): Windows-oriented, and a bit out of date. Used to be more popular!
  • R (2%): Data science/Statistics. Good for its purpose! A bit complex to use for programming.

Some reasons to choose Python

  • Its very readable (this is intentional)
  • Its much simpler than C/C++/C#/Java
  • Its interpreted, not compiled. You don’t turn code into binary before running.
  • Its portable, running on different OSs
  • Its broad, meaning that its suitable for different purposes: software, websites, scripting, data etc.
  • Its popular! This means there’s a lot of support.

And of course, it’s one big reference to Monty Python!

2. Using the Python Interpreter

You might be used to running Python from an IDE (like Spyder), but the simplest way to run Python code is from the interpreter.

This is the same as running it from the console or in your terminal. It’s the thing that interprets your code for the computer.

How you do this depends on your machine. Open up a terminal/shell, then type

python
python3

If that doesn’t work for you, it’s probably because your computer doesn’t know that you have Python installed, because it hasn’t been added to its default search path for applications. That can happen during installation, particularly if it’s not your machine.

Don’t worry - if you’ve got Python working in an IDE, then just use the console.

You know you’re in the Python interpreter when you see

>>>

rather than $ (bash) or > (Windows).

3. An Informal Introduction to Python

We’ll go over a few key Python things in the interpreter.

  • Arithmetic
  • Text
  • Fibonacci!

Arithmetic

The interpreter can act as a calculator

1 + 1
2

Some weird operators:

# Powers
2 ** 5
32
# Floor division
4 // 3
1
# Modulo/remainder
11 % 10
1

Text

Use strings to store literal text

# Single quotes are same as double quotes
'Hello world'
'Hello world'
# Double quotes are same as single quotes
"Hello world"
'Hello world'

Use a backslash to include special characters. Need to use print() to see their effect.

# \n means newline
print("Line1\nLine2")
Line1
Line2
# \t means tab
print("col1\tcol2")
col1    col2

This is bad news if you use Windows, because file paths have backslashes.

Prefix your string with an r, i.e. r"...", to ignore the backslashes

print(r"C:\Users\path\to\script.py")
C:\Users\path\to\script.py
WarningTrailing backslash

You can’t have trailing backslashes, even in a raw string:

print(r"C:\Users\path\to\")
  Cell In[11], line 1
    print(r"C:\Users\path\to\")
          ^
SyntaxError: unterminated string literal (detected at line 1)

Lists and assignment

Use = to define/assign to variables

my_sentence = "Hello world"

Use lists to store multiple values together.

Use square brackets to index and slice

# Lists are created with square brackets []
my_list = ["a", "b", "c"]

# Pick out values with square brackets, count from 0
print(my_list[0])

# Slice to get a range from start:end (excludes end!!)
print(my_list[0:2])

Fibonacci

Let’s write a small program and analyse it!

# Fibonacci series:
# the sum of two elements defines the next
a, b = 0, 1
while a < 10:
    print(a)
    a, b = b, a+b
0
1
1
2
3
5
8

Some features

  • Multiple assignment: a, b = 0, 1 and a, b = b, a+b
  • Loops: while a < 10:

4.10 Intermezzo: Coding Style

This section is at the end of chapter 4, but I want to mention it here.

It outlines some key style guides to keep in mind as you program. Take a look!