Learn Python Functions in 5 minutes with Baby Sharks 🦈
- Chris Wong
- May 16, 2023
- 2 min read
Hi there, little coders! Today we're going to learn about Python functions using our favorite sea friends, the baby sharks! 🦈 Functions are like magic spells that make our code do cool things. Let's dive right in! 🌊

What is a function? 🤔
Imagine you're a baby shark swimming in the ocean. You see a school of fish and you want to tell your shark friends about it. Instead of swimming to each friend and telling them individually, you can use a megaphone to announce it to everyone at once. Functions are like the megaphone, they help us do the same thing many times with less effort.
How to create a function? 🧙♂️
In Python, we can create a function using the def keyword, short for "define". Let's create a function called sing_baby_shark that will help us sing the "Baby Shark" song:
def sing_baby_shark():
print("Baby shark, doo doo doo doo doo doo")
print("Baby shark, doo doo doo doo doo doo")
print("Baby shark, doo doo doo doo doo doo")
print("Baby shark!")
Now our sing_baby_shark function is ready to sing the Baby Shark song! 🎶
How to use a function? 🎤
To use our function, we just need to call its name followed by parentheses (). Let's sing the Baby Shark song:
sing_baby_shark():
When we run this code, it will print the Baby Shark song lyrics! 🦈🎵
Functions with inputs 🐠
Sometimes we want our functions to do different things based on the input we give them. Let's create a function to sing the song for different characters:
def sing_shark_song(character):
print(character + " shark, doo doo doo doo doo doo")
print(character + " shark, doo doo doo doo doo doo")
print(character + " shark, doo doo doo doo doo doo")
print(character + " shark!")
Now we can use our new function to sing the song for different characters:
sing_shark_song("Baby")
sing_shark_song("Mommy")
sing_shark_song("Daddy")
This will sing the song for Baby Shark, Mommy Shark, and Daddy Shark! 🦈👩🦈👨🦈
Functions with outputs 🎁
Sometimes our functions give us something back, like a gift. Let's create a function that tells us how many teeth a shark has:
def count_shark_teeth(shark):
if shark == "Baby":
return 20
elif shark == "Mommy" or shark == "Daddy":
return 50
else:
return "I don't know that shark!"
Now we can use the count_shark_teeth function to learn how many teeth our shark friends have:
baby_teeth = count_shark_teeth("Baby")
print("Baby shark has", baby_teeth, "teeth!")
mommy_teeth = count_shark_teeth("Mommy")
print("Mommy shark has", mommy_teeth, "teeth!")
daddy_teeth = count_shark_teeth("Daddy")
print("Daddy shark has", daddy_teeth, "teeth!")
This will tell us how many teeth Baby, Mommy, and Daddy sharks have! 🦈🦷
Recap 🌟
Congratulations, little coders! You've learned how to create, use, and customize Python functions using baby sharks. Functions make our code more fun and easier to use, just like a megaphone helps us tell our friends about a school of fish. Keep exploring the ocean of coding, and you'll become a Python master in no time! 🦈🌊
Comments