Writing Your First Function
Define and call a function.
Writing Your First Function is a free Coding for Kids lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Coding for Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Time to Build!
Yay! 🎉 Today YOU write your first function.
We will make a recipe that greets people. Let us go! 🚀
The Magic Word def
Every Python recipe starts with the magic word def.
It is short for "define", which means "make".
Pick a Name
Next comes the name. Let us call our recipe greet.
Then we add () and a : like this: def greet(): 📝
Add the Steps
Under the name, we add steps. Push them to the right with spaces. Run it! 👇
def greet():
print("Hi there!")
greet()It Said Hi!
It worked! 🎉 The recipe greet printed "Hi there!"
You just wrote a real Python function. So cool! 😎
The Colon Matters
See the : at the end of def greet():?
It tells Python "the steps are coming next". Never forget it! 🔑
Spaces Are Important
The steps must be indented (4 spaces). Watch what tidy code looks like! ✨
def greet():
print("Hello!")
print("Welcome!")
greet()Two Lines, One Call
We called greet() once, but it printed two lines! 🎈
Both lines were inside the recipe, so both happened.
Make It Yours
Try changing the words inside print. Maybe a joke or a cheer! 😄
def cheer():
print("You can do it!")
print("Go go go!")
cheer()Call It Many Times
Once your recipe is ready, call it as much as you like! 🔁
def greet():
print("Hi there!")
greet()
greet()
greet()You Are Amazing
You built a function from scratch! 🏆
def + name + : + steps = your own recipe. 🍰
Quick Check
Show what you learned! 🌟
Super Coder!
High five! ✋ You wrote your first function today.
Next we learn how to give functions inputs. Exciting! 🎁
Frequently asked questions
Is the “Writing Your First Function” lesson free?
Yes — the full text of “Writing Your First Function” is free to read here on the web, and the Coding for Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Coding for Kids course, upgrade to CoddyKit PRO.
What will I learn in “Writing Your First Function”?
Define and call a function. You practise Coding for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Coding for Kids?
No prior experience is required. Coding for Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Writing Your First Function” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Coding for Kids lesson?
Yes. Every Coding for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What Is a Function?
- Writing Your First Function
- Giving Functions Inputs
- Returning a Result