Introduction
Learning Python is a lot like building with blocks. You don't start with the roof you start with one block, set it down properly, then place the next one on top of it. Skip a step, or rush past something you didn't fully understand, and everything you try to stack on top of it starts to wobble.
That's exactly how these ten concepts work. You can't really understand a loop until you understand a list. You can't understand a function until you've written a few conditional statements by hand. Even something as simple as print() sets you up for f-strings a few sections later. Nothing here exists on its own each concept quietly leans on the one before it, and sets up the one that comes next.
So take your time with this one. Don't skim ahead looking for the "advanced" part there isn't one yet. Understand each block before you place the next, and by the end, you won't just have memorized ten separate ideas. You'll have built a foundation sturdy enough to hold whatever you decide to learn next.
Let's lay the first block.
What Is Python?
Python is a programming language known for reading almost like plain English. Where some languages demand semicolons, brackets, and rigid formatting just to print a sentence, Python lets you write print("Hello") and move on with your day. That simplicity is exactly why it's one of the most widely used languages in the world.
Here's what that looks like in practice. Instagram uses Python behind the scenes to help run parts of its app. Spotify uses it to help decide what song to play next. Netflix uses it to help figure out what show to recommend you. Even simple, everyday things like a script that renames a hundred files at once, or a program that checks the weather and texts you if it's going to rain are the kind of small, practical tasks Python is great at.
You don't need to build anything as big as Netflix to benefit from Python. Even the smallest script that saves you five minutes of repetitive work is Python doing exactly what it's meant to do.
Variables: Giving Your Data a Name
A variable is a labeled container for a value. Instead of retyping someone's age every time you need it, you store it once and refer to it by name:
name = "Josephine Mackylah"
age = 25
city = "Nairobi"
Think of variables the way you'd think of cell references in a spreadsheet. You don't retype the number in B2 everywhere you need it you just reference B2. Variables are Python's version of that same convenience, except the name is whatever you choose, which makes code far easier to read six months later than a spreadsheet full of B2 and D17.
Data Types: Python Needs to Know What Kind of Value It's Holding
Every variable holds a value, and every value has a type. As a beginner, you'll mostly work with four of them:
name = "Josephine Mackylah" # str (string) — text
age = 25 # int (integer) — whole numbers
salary = 14100000.50 # float — decimal numbers
is_active = True # bool (boolean) — True or False
This matters more than it sounds like it should. Python won't let you add a number to a piece of text "Salary: " + 14100000.50 throws an error, because one side is a string and the other is a number. You'd have to convert it first: "Salary: " + str(14100000.50). This single rule that Python cares deeply about type explains more beginner error messages than anything else in the language, so it's worth internalizing early rather than treating it as an annoyance.
print(): Making Python Talk Back to You
print() is how Python shows you something on screen. It's the very first tool you'll reach for, and you'll never stop using it even experienced programmers sprinkle print() statements everywhere while checking their work.
print("Python is","great")
Output:
Python is great
Every time you want to check whether something did what you expected, print() is how you look.
input(): Letting a Human Talk Back to Python
input() does the reverse it pauses your program and waits for someone to type something in:
age = int(input("How old are you? "))
print("You are", age, "years old")
Output (if age = 25)
How old are you? 25
You are 25 years old
You won't use input() in every single program, but it's what makes your code feel interactive instead of static. It's the difference between a script that just runs the same way every time, and one that actually responds to the person using it like a simple quiz, a to-do list that asks what you want to add, or a small calculator that asks for two numbers before doing the math.
F-Strings: The Cleanest Way to Combine Text and Data
Early on, combining text and variables looks clumsy:
print("Hello " + name + "! You are " + str(age) + " years old.")
Output (using name = "Josephine Mackylah" and age = 25 from earlier):
Hello Josephine Mackylah! You are 25 years old.
F-strings fix that. Put an f before the quotation marks, and drop your variables straight into the sentence using curly braces:
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print(f"Hello {name}! You are {age} years old.")
Output (if the person enters "Josephine" and 25):
Enter your name: Josephine
Enter your age: 25
Hello Josephine! You are 25 years old.
No +, no str() conversions, no broken sentences from missing spaces. F-strings are the standard way modern Python code combines text and values, and once you start using them, going back to the old way feels genuinely painful.
Conditional Statements: Teaching Python to Make Decisions
A conditional statement lets your code branch based on a condition the Python equivalent of an Excel IF formula.
score = int(input("Enter score: "))
if score >= 80:
print("Grade A - Excellent")
elif score >= 70:
print("Grade B - Good")
elif score >= 60:
print("Grade C - Average")
elif score >= 50:
print("Grade D - Below Average")
else:
print("Grade F - Failed")
Output (if score = 85):
Enter score: 85
Grade A - Excellent
This is the logic behind almost every decision your code will ever need to make checking a score, deciding whether someone qualifies for something, choosing what message to show based on a condition. Once conditionals click, you'll start noticing them everywhere: a rule you'd normally explain out loud in a sentence is really just a conditional statement, waiting to be written in code.
Loops: Doing Something Once, Then Doing It Again and Again
A loop repeats an action across a collection of items, so you never have to write the same line 50 times:
foods = ["chapati", "ugali", "pilau", "githeri", "mandazi"]
for food in foods:
print(food)
Output:
chapati
ugali
pilau
githeri
mandazi
i = 1
while i <= 10:
print(i)
i += 1
Output:
1
2
3
4
5
6
7
8
9
10
correct_password = "kenya2024"
attempts = 0
while True:
password = input("Enter password: ")
attempts += 1
if password == correct_password:
break
print(f"Correct! It took {attempts} attempts.")
Output (if the person types "jojo" first, then "kenya2024"):
Enter password: jojo
Enter password: kenya2024
Correct! It took 2 attempts.
Notice the three different shapes a loop can take here: a for loop stepping through a known list, a while loop counting up to a number, and a while True loop that keeps going until something specific happens (break). As you keep coding, you'll come across tools that quietly do looping for you behind the scenes but understanding what a loop actually does is what makes those tools make sense later on.
Lists: Python's Way of Holding More Than One Thing
A list is an ordered collection of values, written inside square brackets:
transactions = [1500, 3000, 800, 12000, 450, 2700]
total = 0
for amount in transactions:
total += amount # add each amount to the running total
print(f"Added Ksh{amount} — Running total: Ksh{total}")
Output:
Added Ksh1500 — Running total: Ksh1500
Added Ksh3000 — Running total: Ksh4500
Added Ksh800 — Running total: Ksh5300
Added Ksh12000 — Running total: Ksh17300
Added Ksh450 — Running total: Ksh17750
Added Ksh2700 — Running total: Ksh20450
You can also grab items by position (Python starts counting at 0):
passengers = ["Amina", "Brian", "Cynthia", "David", "Esther"]
print(passengers[0]) # Amina — the first passenger
print(passengers[2]) # Cynthia — the third passenger (position 2)
print(passengers[-1]) # Esther — the last passenger
Output:
Amina
Cynthia
Esther
Position 0 is always the first item not the second which trips up almost every beginner at least once. And -1 is a shortcut for "the last one," so you never have to count how long a list is just to grab its final item.
Functions: Package Your Logic So You Never Rewrite It
A function is a named, reusable block of code. You define it once, then call it as many times as you need. Remember the grading logic from the conditionals section? Here's that exact idea, packaged into a function so you never have to retype it:
def get_grade(score):
if score >= 80:
return "Grade A - Excellent"
elif score >= 70:
return "Grade B - Good"
elif score >= 60:
return "Grade C - Average"
elif score >= 50:
return "Grade D - Below Average"
else:
return "Grade F - Failed"
print(get_grade(85)) # Grade A - Excellent
print(get_grade(42)) # Grade F - Failed
Output:
Grade A - Excellent
Grade F - Failed
The moment you find yourself copy-pasting the same five lines of grading logic into a second place, that's the signal to wrap it in a function instead. Now, no matter how many scores you need to grade, you call get_grade() once instead of retyping the same if/elif chain over and over.
The Modulus Operator: The Most Underrated Symbol in Python
The modulus operator, written as %, gives you the remainder after division not the answer itself:
print(10 % 3) # 1 (10 divided by 3 leaves a remainder of 1)
print(15 % 5) # 0 (15 divides evenly by 5)
Output:
1
0
It looks like a small, obscure trick, but it solves a very common problem: figuring out whether a number is even or odd, or whether it divides evenly into groups.
numbers = [12, 7, 18, 5, 30, 9]
count = 0
for number in numbers:
if number % 2 == 0:
count = count + 1
print(count) # 3 — there are three even numbers in the list
Output:
3
booking_id = 47
if booking_id % 2 == 0:
print("Even-numbered booking")
else:
print("Odd-numbered booking")
Output:
Odd-numbered booking
It also shows up when batching work for example, processing a big list of items in groups of 10 and needing to know exactly when you've hit the boundary of a new batch. It's a small tool, but it's one of those things you don't appreciate until the exact moment you need it and realize nothing else does the job as cleanly.
Putting It All Together: A Simple Ticket Receipt
Let's take some of the earliest blocks you laid down variables, input(), print(), f-strings, and basic arithmetic and use them to build something real: a mini program that prints out a bus ticket receipt.
print("=" * 40)
print(" BUS TICKET BOOKING")
print("=" * 40)
passenger_name = input("Enter passenger name: ")
route = input("Enter route: ")
fare = int(input("Enter fare (ksh): "))
booking_fee = 10
total = fare + booking_fee
print()
print("=" * 40)
print(" TICKET")
print("=" * 40)
print(f"Passenger : {passenger_name}")
print(f"Route : {route}")
print(f"Fare : Ksh{fare}")
print(f"Booking Fee : Ksh{booking_fee}")
print("-" * 40)
print(f"TOTAL : Ksh{total}")
print("=" * 40)
print(" THANK YOU FOR BOOKING")
print("=" * 40)
Output (if the person enters "Josephine Mackylah", "Nairobi - Mombasa", and 1200)
========================================
BUS TICKET BOOKING
========================================
Enter passenger name: Josephine Mackylah
Enter route: Nairobi - Mombasa
Enter fare (ksh): 1200
========================================
TICKET
========================================
Passenger : Josephine Mackylah
Route : Nairobi - Mombasa
Fare : Ksh1200
Booking Fee : Ksh10
----------------------------------------
TOTAL : Ksh1210
========================================
THANK YOU FOR BOOKING
========================================
There's more going on here than it looks like at first glance. Notice "=" * 40 that's Python repeating a character 40 times to draw a clean divider line, instead of you typing out forty equals signs by hand. It's a small trick, but it's the kind of shortcut that makes your output look intentional instead of thrown together.
The program then uses input() three times to collect the passenger's name, route, and fare turning a static script into something that actually responds to whoever's using it. Notice that the fare is wrapped in int(): that's because input() always hands back text, even if someone types a number, so we have to explicitly convert it before we can do math with it. Skip that step, and Python will refuse to add it to booking_fee a perfect real-world example of the "Python cares about data types" rule from earlier.
From there, it's just a variable holding a fixed fee, one line of arithmetic to calculate the total, and a series of f-strings to lay everything out neatly lining up the labels with spacing so the receipt actually looks like a receipt.
Run it, and you get a clean, ticket-style printout from about a dozen lines of code. That's variables, data types, input(), print(), and f-strings five of the ten blocks you just learned all working together to produce something that genuinely feels useful.
You don't have to master everything at once. Learn one block well, set it down properly, and place the next one on top. By the time you reach the last line of that receipt, you'll notice you're already using half the concepts you just learned without even having to think about it.
Top comments (2)
The structure and flow is really good. I would love to see more of these.
Thank you Leslie