🎛️ Parameter

6th Grade 💻 Coding

A parameter is an “empty slot” in a function that gets filled with a different value each time you call it. It lets the same function work with different information every time.

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

In the function def square(n): return n * n, n is a parameter. When you write square(4), n gets the value 4, and the function gives back 16. The value you pass in the call (4) is called an argument, but in everyday talk people use the two words almost the same way.

A function can have several parameters, separated by commas: def area(width, height): return width * height. In Scratch, when you make a block in “My Blocks,” you can add an “input” to it — for example a number of steps — and that’s exactly a parameter.

For example

  • A “draw square” function with a “size” parameter: a 50-step square or a 200-step square from the same function.
  • In the print function, the text in the parentheses is the argument: print("Hi").
  • A coffee machine with “small” and “large” buttons: the size is like a parameter — same machine, different result depending on what you pick.

📌 Remember: Parameter = a slot in the function that you fill on every call.

Quick quiz

  1. What is a parameter?

  2. If def square(n): return n * n, what does square(4) give?

  3. How do you separate several parameters?

🔎 Ask Thinkapedia another question