How Planning a Birthday Party Helped Me Understand Python Functions


It was my best friend Rhea’s 21st birthday, and I had big plans:
🎈 Surprise party.
🎁 Personalized gifts.
🍕 Pizza from her favorite place.
🎶 A playlist of her throwback songs.
But somewhere between booking the cake and texting 17 people about the party time, I realized I was doing the same things again and again.
Sending similar messages with different names.
Calculating the share of the cake cost per person.
Printing labels for gift bags with each friend’s name.
And that’s when it hit me:
This is exactly what Python functions are for.
If you’ve ever repeated a task (in real life or in code), you’ve already felt the need for a function—you just didn’t know its name yet.
In this post, we’ll explore what functions in Python are, how to write them, and why they make your code (and life) a whole lot easier—using my party planning as the example.
📌 So, What Is a Function in Python?
A function is like a mini-program.
It’s a block of code that performs a specific task and can be reused whenever needed.
Think of it like this:
I didn’t write a unique message for each person I invited.
I wrote one message template and just changed the name.
That’s exactly what a function does.
🧠 Why Use Functions?
Here’s what functions did for my party plan—and what they can do for your code:
✅ 1. Avoid Repetition
Instead of rewriting the same instructions, I wrote one function to:
Send invites
Split bills
Create gift bag labels
✅ 2. Keep Things Organized
Each part of the party had its own function: invitations, payments, food orders. This made it easy to test and tweak one thing at a time.
✅ 3. Save Time and Headache
Once a function is defined, you just call it. No need to rewrite or rethink logic again and again.
💬 Step-by-Step: Creating Functions in Python
Let’s walk through the basics using real scenarios from Rhea’s party.
🎈 Step 1: Defining a Function
We’ll start with a simple one—sending a birthday invite.
To use this function:
🖨️ Output:
That’s it! We wrote it once and reused it for everyone.
💸 Step 2: Calculating Per Person Cost
Let’s say the pizza and cake cost ₹2,400 and we had 8 people splitting it.
Without a function:
With a function:
Now, if next time we have a 12-person dinner or a ₹3600 bill, we can just call the function again:
🏷️ Step 3: Creating Gift Bag Labels
Each friend got a little bag with a thank-you note. The label had their name printed with a sweet message.
We can automate that too!
Output:
Easy to print out for every guest!
🔁 Functions with Multiple Parameters
You’re not limited to one input. You can pass multiple values too.
Here’s a food order example:
Output:
🔄 Reusable and Reliable: The Power of Return
Some functions don’t just print—they return a value, which you can store and reuse.
Example: Let's track RSVP confirmations.
Output:
Returning values makes your functions flexible—you can save results, combine them, or use them in other logic.
🧰 Summary: Key Parts of a Function
Term | Meaning |
def | Keyword to start a function |
function() | The name used to call it |
Parameters | Inputs you pass to customize the function |
return | Optional keyword to send back a value |
🎉 Final Thought: You Already Think in Functions
When I look back at the party, I realize:
I grouped tasks naturally
I avoided doing things twice
I created "templates" for messages, costs, labels
Which is exactly what Python functions help you do—with code.
If you’ve ever:
Repeated code
Wanted to organize your script
Struggled with debugging
...then functions are your next best friend.
🏁 Try This Out:
Challenge:
Create a simple function that takes a name and a gift item, and prints a thank-you message.
Output:
It’s small, but it’s a start.
Just starting with functions?
Pick a real-life task (greeting friends, calculating bills, printing reminders) and turn it into a Python function. You’ll be amazed at how much easier coding—and life—becomes.
Let me know if you’d like a free cheat sheet of 10 beginner-friendly function exercises!
Subscribe to my newsletter
Read articles from Kumkum Hirani directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
