How Does Beginner Python Tutorial 84 - Arguments and Parameters Work?

A function is like a robot that needs instructions to do its job, and arguments are those instructions.

Imagine you have a friend who loves to draw. Every time you ask them to draw something, they need to know what to draw. If you say "Draw a cat," they make a cat. If you say "Draw a dog," they make a dog. The words "cat" and "dog" are like arguments, they tell your friend what to do.

In Python, when we write a function, we can give it parameters, which are like the spaces where arguments go. Think of parameters as the empty boxes on a recipe card, you fill them in with real ingredients (the arguments) when you use the recipe.

For example:

def draw_picture(shape):
 print("Drawing a", shape)

Here, shape is a parameter. When we call draw_picture("cat"), "cat" becomes the argument, and it fills in the box for shape.

So functions use parameters to receive arguments, like your friend uses instructions to know what to draw.

Take the quiz →

Examples

  1. A function called add takes two numbers, like 3 and 4, and returns their sum (7). The numbers are the arguments, and the names inside the function (a and b) are the parameters.
  2. When you call a function, the values passed to it are called arguments, and the variables that receive them are called parameters.
  3. Imagine you have a function named greet, which takes a name. When you write greet('Alice'), 'Alice' is an argument, and the parameter inside the function might be called name.

Ask a question

See also

Discussion

Recent activity

Categories: Science · Python· Arguments· Parameters