Python is a general-purpose programming language known for reading almost like English. It is the most common first language for good reason: you spend your energy on ideas rather than punctuation.
This guide covers what Python is for, how to get it running, and the order to learn things in.
What Python is good at#
- Automation — renaming a thousand files, filling spreadsheets, scraping a page, sending reports
- Data work — cleaning, analysing and charting information
- Back-end web development — with Django or Flask
- Scripting and glue — small tools that connect other tools
- Learning to program — the syntax stays out of your way
It is a weaker choice for iPhone and Android apps, and for anything running inside a web browser, where JavaScript is the natural fit.
Getting Python running#
Two options, and both are fine:
- Online editor — no installation, works on any machine, good for the first week.
- Installed locally — needed the moment you want to work with your own files. Follow how to install Python.
Check an installation from a terminal:
python --versionIf that prints something like Python 3.12.4, you are ready. If it errors, the install guide covers the usual causes.
Your first program#
Create a file called hello.py with one line:
print("Hello, world!")Then run it:
python hello.pyWalked through in detail in your first Python program.
The syntax you will use every day#
Variables#
name = "Ada"
age = 36
height = 1.7
is_student = FalseNo type declarations, no semicolons. See Python variables explained.
Getting input and showing output#
name = input("What is your name? ")
print(f"Nice to meet you, {name}.")That f before the quotes makes an f-string, which lets you drop variables straight into text. It is the most convenient thing in the language.
Decisions#
marks = 82
if marks >= 80:
print("Distinction")
elif marks >= 50:
print("Pass")
else:
print("Try again")Indentation is not decoration in Python — it is how the language knows what is inside the if. See Python if/else statements.
Repetition#
for item in ["pen", "book", "bag"]:
print(item)
count = 3
while count > 0:
print(count)
count -= 1Collections#
scores = [10, 8, 9] # list
student = {"name": "Ada", "score": 90} # dictionary
print(scores[0]) # 10
print(student["name"]) # AdaDetail in Python lists and Python dictionaries.
Functions#
def bmi(weight_kg, height_m):
return round(weight_kg / (height_m ** 2), 1)
print(bmi(70, 1.75)) # 22.9Reading and writing files#
This is where Python starts feeling genuinely useful.
with open("notes.txt", "w") as f:
f.write("First line
")
with open("notes.txt") as f:
print(f.read())The with block closes the file for you, even if something goes wrong.
Using other people’s code#
Python ships with a large standard library, and there is a package for almost everything else.
import random
print(random.randint(1, 6)) # a dice rollpip install requestsA learning order that works#
- Print, variables, input, data types
- Conditions, then loops
- Lists and dictionaries
- Functions
- Reading and writing files
- Errors and
try / except - Importing modules and installing packages
- A real project — do not skip this
Most people stall around step 4 because they keep watching tutorials instead of building. Break the pattern at step 3 by making something small.
Questions people ask#
Python 2 or Python 3?
Python 3. Python 2 reached end of life in 2020. If a tutorial uses print "hello" without brackets, it is out of date — find a newer one.
How long until I can build something useful?
With consistent practice, a few weeks is enough for genuinely useful small scripts — a file organiser, a data cleaner, a reminder tool. Those small wins are what keep people going.
Do I need an IDE?
VS Code with the Python extension is free and does everything you need. See VS Code setup for beginners.
What is a virtual environment?
A separate folder of packages for one project, so two projects can use different versions without clashing. Not urgent on day one, worth learning by the time you have two projects.
Where to go next#
- How to install Python properly
- Your first Python program
- Build a number guessing game
- The full Python learning path — every guide here in reading order
- Reading and writing files in Python
- Python virtual environments explained