🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·
🐍Free Course

Python

Learn programming with the world's most popular language for beginners. Variables, loops, functions, lists, and more.

21 Lessonsbeginner

Lessons

1

What is Programming

Programming is giving the computer step-by-step instructions. Just like a recipe tells you how to make food, code tells the computer what to do. We write code in a programming language (like Python) that both humans and computers can understand.

Python was invented in 1991 — but it's more popular now than everA <strong>comment</strong> starts with # — Python ignores it; it's a note for humansprint() is a <strong>built-in function</strong> — Python gives you hundreds of these for free
2

Variables

📚 What are Variables? A variable is a named container that holds a value in your program. Think of it like a labelled box: you write a name on the outside, put something inside, and come back later to find it by name. In Python you create one with a simple assignment: name = value.

Variable names <em>cannot</em> start with a number: <code>1score</code> is invalid, <code>score1</code> is fineUse underscores for multi-word names: <code>high_score</code> (snake_case is the Python style)Python figures out the type automatically — no need to say 'this is a number'
3

Data Types

📚 What are Data Types? Every value in Python has a type that tells the computer what kind of data it is and what operations make sense for it. Python has four main types: int (whole numbers like 5), float (decimal numbers like 3.14), str (text like 'hello'), and bool (True or False). Python detect…

<code>type(x)</code> tells you what type <code>x</code> is — brilliant for debuggingConvert between types: <code>int("5")</code> → 5, <code>str(42)</code> → "42", <code>float("3.14")</code> → 3.14True and False are capitalised — <code>true</code> (lowercase) causes an error
4

Conditions (if/else)

📚 What are conditions? Conditions let your program **make decisions** instead of always doing the same thing. You ask a yes/no question in code; if the answer is true, one block runs; if not, you can run a different block with `else` or chain extra checks with `elif`.

Combine conditions with <code>and</code> (both must be True) or <code>or</code> (at least one must be True)<code>not</code> flips a boolean: <code>not True</code> is <code>False</code>You can nest if statements inside other if statements (called <strong>nested conditions</strong>)
5

Loops

📚 What are loops? Loops are commands that **repeat** work automatically so you do not type the same lines again and again. A `for` loop is great when you know how many steps you want (or you want to walk through a list). A `while` loop keeps going **as long as** a condition stays true.

<code>range()</code> does NOT include the end number — <code>range(5)</code> is 0,1,2,3,4An <strong>infinite loop</strong> (<code>while True:</code>) runs forever — you need a <code>break</code> inside to exitLoops can be nested inside other loops (a loop inside a loop — like a grid)
6

Functions

📚 What are Functions? A function is a named, reusable block of code. You write it once with def function_name():, then call it as many times as you need just by writing its name. Functions can accept inputs (parameters) and send back a result with return. They are the most important tool for keepi…

Functions can call other functions — this is how large programs are organisedA function should do <em>one thing well</em> — short, focused functions are easier to debugPython has hundreds of <strong>built-in functions</strong> you already use: <code>print()</code>, <code>len()</code>, <code>range()</code>
7

Arrays / Lists

📚 What are Lists? A list is an ordered collection that holds multiple values in a single variable. Instead of creating score1, score2, score3 separately you write scores = [85, 92, 78] and handle all three at once. Lists keep their order, allow duplicates, and can hold any type of value.

Lists can hold mixed types: <code>[1, "hello", True, 3.14]</code>Lists can hold other lists (nested): <code>[[1,2],[3,4]]</code> — useful for gridsSlicing: <code>nums[1:4]</code> returns items at index 1, 2, 3 (not 4)
8

Objects / Dictionaries

📚 What are Dictionaries? A dictionary stores data as key-value pairs. Instead of remembering that index 3 holds the age, you use a descriptive key like 'age'. Python dictionaries are written with curly braces: player = {'name': 'Alex', 'score': 100}. You look up values by key: player['name'] gives…

Keys must be unique — you can't have two entries with the same keyKeys are usually strings, but can be numbers or tuplesValues can be anything — even another dictionary or a list
9

Debugging Basics

📚 What is Debugging? Debugging is the process of finding and fixing mistakes (bugs) in your code. Every programmer debugs every day. The word 'bug' comes from 1947 when an actual moth was found inside a computer causing it to fail! Today bugs are logic errors, typos, or wrong assumptions in your c…

The word 'bug' comes from a literal moth found in a 1940s computer that caused a faultPython's <strong>traceback</strong> shows the exact chain of calls that led to the error — read it bottom to top<code>print()</code> debugging is used by professionals daily — simple but powerful
10

String methods

📚 What are String Methods? A string method is a built-in tool that transforms or inspects text. Call them with a dot: 'hello'.upper() gives 'HELLO'. Strings in Python are immutable, so methods always return a new string instead of changing the original.

Python strings are <strong>immutable</strong> — no method changes the original; they all return new stringsThere are over 40 built-in string methods in Python<code>f"{name.title()}"</code> combines f-strings with <code>.title()</code> for clean name formatting
11

Try and Except

📚 What is Try/Except? Pythia says: 'Even the best code faces unexpected situations - a file that does not exist, a user who types letters instead of numbers. try/except is your safety net!'

Exceptions are objects in Python — they have a <code>.args</code> and <code>.__class__.__name__</code>You can <strong>raise</strong> your own exceptions: <code>raise ValueError("Age must be positive")</code>Catching bare <code>except:</code> (no type) is bad practice — it hides bugs you didn't intend to catch
12

List Comprehensions

📚 What are List Comprehensions? A list comprehension is a compact, readable way to build a new list from another list in a single line. Instead of writing a for loop, appending each item, you write: new_list = [expression for item in old_list]. You can add a filter with an if at the end.

List comprehensions are typically <strong>30–50% faster</strong> than equivalent for-loops in PythonPython also has <strong>dict comprehensions</strong>: <code>{k: v for k, v in pairs}</code> and <strong>set comprehensions</strong>Generator expressions look the same but use <code>()</code> — they save memory by producing items one at a time
13

Reading and Writing Files

📚 What is File I/O? File I/O (Input/Output) lets your program read data from files and save results back to disk. Without files, every time you close the program all data is lost. With files, you can load saved games, read configuration, process datasets, and log events.

Always use <code>with open()</code> — it's called a <strong>context manager</strong> and guarantees the file is closedAdd <code>encoding='utf-8'</code> to handle emoji and non-ASCII characters: <code>open('f.txt', 'r', encoding='utf-8')</code>Python's <code>csv</code> module makes reading CSV files even easier than doing it manually
14

Modules and import

📚 What are Modules? A module is a file of Python code you can reuse. Python comes with a huge standard library of modules covering maths, dates, randomness, file handling, networking, and much more. Rather than writing everything from scratch you simply import what you need.

Python's standard library has over <strong>200 modules</strong> — covering everything from email to HTML parsingPyPI (Python Package Index) hosts over <strong>500,000 third-party packages</strong> you can install with pipModules are only loaded <strong>once</strong> per program run — Python caches them for efficiency
15

Default Arguments

📚 What are Default Arguments? Default arguments let you specify a fallback value for a function parameter. If the caller does not provide that argument, the default is used. This makes functions more flexible: callers can omit optional inputs, keeping calls short while still allowing full control …

Default values are evaluated <strong>once</strong> at function definition time, not each call — this is why mutable defaults are dangerousThe safe pattern for a mutable default is: <code>def add(item, lst=None): if lst is None: lst = []</code><code>**kwargs</code> is how Python's own <code>dict()</code>, <code>open()</code>, and most libraries accept flexible named options
16

Slicing

📚 What is Slicing? Slicing extracts a portion of a list or string using the syntax [start:end:step]. It returns a new list or string - the original is unchanged. Slicing is one of Python's most expressive features and is used constantly in data processing.

Slices work on <strong>strings, lists, tuples</strong> and any custom sequence type<code>list[:]</code> creates a <strong>shallow copy</strong> of the entire list — useful for avoiding mutation bugsNumPy arrays (used in data science and AI) heavily rely on slice syntax
17

enumerate and zip

📚 What are enumerate and zip? enumerate() and zip() are built-in functions that make loops more powerful. enumerate() adds a counter to any iterable, giving you both the index and the value. zip() pairs up items from two or more lists so you can process them together in one loop.

Both <code>enumerate</code> and <code>zip</code> return <strong>lazy iterators</strong> — wrap in <code>list()</code> to materialise them<code>dict(zip(keys, values))</code> is the fastest way to build a dictionary from two lists<code>zip(*matrix)</code> transposes a 2D list (swaps rows and columns)
18

Sets (unique items)

📚 What are Sets? A set is an unordered collection that stores only unique items - duplicates are automatically removed. If you add the same item twice, the set only keeps one copy. Sets are extremely fast for checking membership (if x in my_set) which is far quicker than searching a list.

Set membership (<code>in</code>) is <strong>O(1)</strong> average — checking a million-item set is as fast as checking a 10-item setLists have O(n) membership — a set is ~100,000× faster for large collectionsPython also has <code>frozenset</code> — an immutable set that can be used as a dictionary key
19

Lambda (small functions)

📚 What are Lambda Functions? A lambda is a tiny, anonymous function written in one line: lambda arguments: expression. It returns the result of the expression automatically. Lambdas are perfect when you need a quick function to pass to map(), filter(), or sorted() without writing a full def.

Lambdas are <strong>function objects</strong> — they can be stored in variables, passed as arguments, and returned from functionsThey cannot contain statements (if/else/for/while are not allowed inside — only expressions)PEP 8 advises: if you assign a lambda to a name, just use <code>def</code> instead — <code>double = lambda x: x*2</code> should be <code>def double(x): return x*2</code>
20

Recursion Basics

📚 What is Recursion? Recursion is when a function calls itself to solve a smaller version of the same problem. It keeps calling itself with smaller inputs until it hits a base case - the stopping condition. Recursion sounds mind-bending at first but it is a powerful technique for problems that nat…

Python's default recursion limit is <strong>1000 calls</strong> — you can raise it with <code>sys.setrecursionlimit()</code> but this is rarely neededEvery recursive solution can be rewritten as a loop — sometimes one is clearer than the other<strong>Tail recursion</strong> (where the recursive call is the last thing) can be optimised by compilers, but Python does <em>not</em> do this optimisation
21

Dictionary Methods

📚 What are Dictionary Methods? Python dictionaries come with powerful built-in methods for accessing, modifying, and iterating over their data. Learning these methods makes working with structured data much cleaner and prevents common bugs like KeyError crashes.

As of Python 3.7+, dictionaries preserve <strong>insertion order</strong> — they're no longer random<code>collections.defaultdict</code> auto-creates missing keys: <code>defaultdict(int)</code> returns 0 for any missing keyDict comprehensions create dicts in one line: <code>{k: v*2 for k, v in prices.items()}</code>

Start learning Python free today

AI tutoring · quizzes · projects · works on any device