Six modules — from a blank editor to writing your own functions
Every module below includes a real, editable Python editor — powered by Pyodide, running entirely in your browser.
1Getting Started with Python
Setting up your environment and running your very first line of code.
What Is Python, and Why Learn It?
Python is a high-level, general-purpose programming language known for readable syntax that reads almost like plain English.
📖 Readable
Clean syntax with minimal punctuation — code that's easy to write and re-read later.
🧩 Versatile
Used for web apps, data science, AI/ML, automation, scripting, and more.
🌱 Beginner-Friendly
A gentle learning curve, with one of the largest communities for support.
📈 In-Demand
Consistently ranked among the most requested skills in tech job listings.
Installing Python & Choosing an Editor
Two decisions before you write a single line.
- Download the latest version from python.org/downloads
- On Windows, check "Add Python to PATH" during install
- macOS and Linux often ship with Python — verify the version
- Confirm it worked by checking the version in a terminal
| VS Code | Free, lightweight, huge extensions — great default |
| PyCharm | Full IDE, deep debugging, popular for larger projects |
| Jupyter Notebook | Cell-based, inline output — ideal for experimentation |
This course uses VS Code in examples, but any of these will work fine.
Your First Program: Hello World
Every language tradition starts here — let's run it two different ways.
# hello.py
print("Hello, World!")
Save code in a .py file, then run it from the terminal with the python command.
$ python
>>> print("Hello, World!")
Hello, World!
>>> 1 + 1
2
The REPL ("Read-Eval-Print Loop") runs one line at a time — perfect for quick tests.
▶️ Try It Yourself — Live Python Editor
Comments & Code Style
Code is read far more often than it's written — style matters from day one.
2Variables & Data Types
How Python stores, labels, and converts the values your programs work with.
Variables & Assignment
A variable is a name that points to a value stored in memory.
name =
"Ada"
age = 28
height_m = 1.68
is_student = False
# Multiple assignment in one
line
x, y, z = 1, 2, 3
Core Data Types
Five building-block types you'll use in nearly every program.
| Type | Example | Meaning |
|---|---|---|
| int | 42 | Whole numbers, positive or negative |
| float | 3.14 | Numbers with a decimal point |
| str | "hi" | Text, wrapped in quotes |
| bool | True | Exactly one of True or False |
| NoneType | None | Represents "no value" |
type(42) → <class 'int'> · int("5") → 5 · str(5) → "5" · float(5) → 5.0
🧩 Puzzle: Sort Each Value by Its Type
Select a value, then click the type it belongs to.
Strings, In Depth
word = "Python"
word[0] # 'P'
word[-1] # 'n'
word[0:3] # 'Pyt'
len(word) # 6
"Hi".upper() # 'HI'
" hi ".strip() # 'hi'
"a,b".split(",") #
['a','b']
"-".join(["a","b"]) # 'a-b'
print(f"{name} is {age} years old") # Ada is 28 years old
Basic Input & Output
name =
input("What is your name? ")
print(f"Hi, {name}!")
▶️ Try It Yourself — Live Python Editor
3Operators & Control Flow
Comparing values and teaching your programs to make decisions.
Operators
| Category | Operators | Meaning |
|---|---|---|
| Arithmetic | + - * / | add, subtract, multiply, divide |
| // % ** | floor divide, modulo, exponent | |
| Comparison | == != | equal to, not equal to |
| < > <= >= | less/greater than (or equal) | |
| Logical | and | true if BOTH sides are true |
| or / not | true if EITHER side is true / negation |
7 // 2 → 3 · 7 % 2 → 1 · 2 ** 5 → 32 · 5 > 3 and 2 < 4 → True
Conditional Statements: if / elif / else
temperature = 28
if temperature > 30:
print("It's hot!")
elif
temperature > 20:
print("Nice
weather.")
else:
print("Bring a jacket.")
# Output: Nice weather.
if
Checked first. If True, its block runs and the rest is skipped.
elif
Checked only if the above was False. You can chain as many as needed.
else
Runs only if every condition above was False. Always optional.
Truthy & Falsy Values
Every value in Python can be evaluated as True or False in a condition — even non-boolean ones.
🧩 Puzzle: Truthy or Falsy?
Select a value, then click Truthy or Falsy.
Nested Conditionals
if age
>= 18:
if
has_ticket:
print("Welcome
in!")
else:
print("Please
buy a ticket.")
else:
print("Must be 18 or older.")
▶️ Try It Yourself — Live Python Editor
4Loops & Iteration
Teaching your programs to repeat work without repeating code.
For Loops & range()
A for loop runs its block once for every item in a sequence.
fruits
= ["apple", "banana", "kiwi"]
for fruit in fruits:
print(fruit)
#
apple / banana / kiwi
for i in range(5): print(i) → 0 1 2 3 4 · range(2, 10, 2) → 2 4 6 8 (stop is never included)
While Loops
Repeats as long as a condition stays true — used when you don't know the count in advance.
count
= 0
while count < 3:
print(f"Count is
{count}")
count += 1 # don't forget this!
break, continue & else on Loops
break
Immediately exits the loop entirely, skipping anything left.
continue
Skips just this one iteration and moves to the next.
else
Runs only if the loop finished WITHOUT hitting break.
Puzzle: Trace a Nested Loop
A loop inside a loop — put these execution events back in the order they actually happen for for row in range(1,3): for col in range(1,3): print(row,col).
▶️ Try It Yourself — Live Python Editor
5Core Data Structures
Lists, dictionaries, tuples, and sets — Python's built-in ways to organize data.
fruits = ["apple","banana"]
fruits.append("mango")
fruits[1] =
"pear"
fruits.remove("apple")
Ordered, mutable, allows duplicates & mixed types, indexed from 0.
person = {"name":"Ada","age":28}
person["age"] = 29
person["city"] = "Lagos"
Keys unique & immutable, mutable values, insertion order preserved since Python 3.7.
point = (4, 7)
x, y = point
point[0] = 9 # TypeError!
Once created, contents can never change. Use for fixed data like coordinates.
nums = {1, 2, 2, 3} # {1,2,3}
a = {1,2}; b = {2,3}
a | b # union
a & b # intersect
Automatically drops duplicates. Great for membership checks and comparisons.
Choosing the Right Data Structure
| Structure | Syntax | Ordered | Mutable | Duplicates | Good For |
|---|---|---|---|---|---|
| List | [ ] | Yes | Yes | Yes | A shopping list, a queue of tasks |
| Tuple | ( ) | Yes | No | Yes | A coordinate pair, RGB color values |
| Dictionary | {k: v} | Yes* | Yes | By key | A user profile, a lookup table |
| Set | { } | No | Yes | No | Unique tags, fast membership checks |
* Dictionaries preserve insertion order (since Python 3.7), but are accessed by key, not position.
🧩 Puzzle: Which Structure Fits Best?
Select a scenario, then click the data structure that fits it best.
▶️ Try It Yourself — Live Python Editor
6Functions Basics
Packaging code into reusable, nameable blocks.
Defining Functions
def
greet(name):
"""Return a greeting for
name."""
return f"Hello, {name}!"
message =
greet("Ada")
print(message) # Hello, Ada!
def
Keyword that starts a function definition.
greet(name)
The function's name and its parameter(s).
return
Sends a value back to wherever it was called.
Default & Keyword Arguments
def greet(name, greeting="Hi"):
return f"{greeting},
{name}!"
greet("Ada") # Hi, Ada!
greet("Ada", "Yo") # Yo, Ada!
def describe(name, age, city):
return f"{name}, {age},
{city}"
describe(city="Lagos", name="Ada", age=28)
Scope, and *args / **kwargs
x = 10
# global scope
def show():
y = 5 # local
scope
print(x, y) # 10 5
show()
print(y) # NameError!
def total(*args): return sum(args) · total(1,2,3) → 6 · def info(**kwargs): print(kwargs)
🧩 Puzzle: Label the Parts of a Function Call
Given def greet(name, greeting="Hi"): return f"{greeting}, {name}!" — sort each term below.
▶️ Try It Yourself — Live Python Editor
Course Recap — Part 1
- Installed Python, chose an editor, and ran your first Hello World program
- Stored data in variables using Python's core types: int, float, str, bool, None
- Formatted and manipulated text with string slicing, methods, and f-strings
- Made decisions with if / elif / else, and understood truthy vs falsy values
- Repeated work with for and while loops, using break, continue, and else
- Organized data with lists, dictionaries, tuples, and sets
- Wrote your own reusable functions with parameters, defaults, and *args/**kwargs
Master Cheat Sheet
Every core reference table from the course, in one place.
Core Types
| int | 42 |
| float | 3.14 |
| str | "hi" |
| bool | True / False |
| NoneType | None |
Operators
| // % ** | floor div, modulo, power |
| == != < > | comparisons |
| and / or / not | logical |
Data Structure Syntax
| List | [1, 2, 3] |
| Tuple | (1, 2, 3) |
| Dict | {"k": "v"} |
| Set | {1, 2, 3} |
Function Anatomy
def
name(param="default"):
return value
Glossary — Flip to Reveal
Click any card to flip it and see the definition.
Final Comprehensive Assessment
15 mixed questions spanning all six modules. Your live score is tracked at the top.
Resources & Links
Official docs mentioned in this course.