🧩 Function

5th Grade 💻 Coding

A function is a group of instructions that you give a name. Once you define it, you can run it (“call” it) anywhere and as often as you like.

Free · US Letter · no sign-up
Google Classroom Save to Pinterest Email me

In Python you define a function with def: def greet(name): print("Hello " + name). After that, greet("Liam") shows “Hello Liam,” and greet("Sofia") shows “Hello Sofia.” In Scratch you make a new block in the “My Blocks” category.

Functions save you from writing the same thing over and over, keep a program organized and make fixes easier: a bug you fix inside a function is fixed everywhere the function is used. They also hide details — print is a function we use without knowing how it works on the inside.

For example

  • A “draw a star” function that you use ten times to draw a night sky.
  • A game has functions like “start level,” “move enemy” and “show score.”
  • When you ask a friend to “make a sandwich,” you don’t list every step — “make a sandwich” is a name for a list of actions, just like a function.

📌 Remember: Function = a recipe with a name. Write it once, use it many times.

Quick quiz

  1. What is a function?

  2. Which word defines a function in Python?

  3. What do you call running a function?

🔎 Ask Thinkapedia another question