Skip to content
beginner

Function Arguments and Return Values

Learning Python is a lot like learning how to give and follow instructions in real life. Imagine asking someone to make you a sandwich: you need to tell…

Published 2026-05-11Updated 2026-05-158 min read

Learning Python is a lot like learning how to give and follow instructions in real life. Imagine asking someone to make you a sandwich: you need to tell them what kind of bread, what fillings, and whether you want it toasted. In programming, functions are like those helpers—they can do things for you, but you need to give them the right information. That’s where function arguments and return values come in.

Understanding how to pass information into a function and get results back is a big step toward writing powerful and flexible Python code. Let’s break down these concepts and see how they can help you solve real problems as you learn Python.


What Are Function Arguments?

Function arguments are pieces of information you give to a function so it can do its job. Think of them as the ingredients you hand to your sandwich maker. Without them, your helper wouldn’t know what kind of sandwich you want!

Arguments make functions flexible. Instead of writing a new function for every situation, you can write one function that works with different inputs.

For example, imagine you want a function that says hello to someone. Instead of writing a new function for every name, you can create one function and give it the name as an argument.

def greet(name):
    print("Hello, " + name + "!")

greet("Alice")

Quiz Question 1

Question: What is the main purpose of using parameters in a Python function?

  • A) To allow the function to accept different input values each time it is called
  • B) To print information to the screen
  • C) To define the name of the function
  • D) To end the function early

Understanding Parameters and Arguments

It’s easy to mix up the words parameters and arguments. Here’s a simple way to remember the difference:

Diagram showing a function definition with a parameter box and a function call with an argument value, with arrows indicating how the argument fills the parameter when the function is called.

This diagram illustrates how parameters are placeholders in a function definition and arguments are the actual values passed in when the function is called.

  • Parameters are the names you use in the function’s definition. They’re like empty boxes waiting to be filled.
  • Arguments are the actual values you give to the function when you use (call) it.

For example, when you define a function, you might write:

def greet(name):
    print("Hello, " + name + "!")

Here, name is a parameter. Later, when you call the function:

greet("Alice")

“Alice” is the argument. The parameter name gets filled with the argument “Alice” when the function runs.

Tip:
Parameters = Placeholders in the definition.
Arguments = Actual values you pass in.


Quiz Question 2

Question: Which of the following statements is true about parameters and arguments in Python?

  • A) Parameters and arguments are always the same thing
  • B) Parameters are used in the function definition; arguments are the values passed when calling the function
  • C) Arguments are only used in print statements
  • D) Parameters can only be numbers

Types of Function Arguments

Python lets you use different types of arguments to make your functions even more flexible:

  • Positional arguments: Values are assigned to parameters based on their position.
  • Keyword arguments: You specify which parameter gets which value by name.
  • Default arguments: You can give a parameter a default value, so it’s optional when calling the function.

Here’s an example with all three:

def describe_pet(animal, name="Unknown"):
    print(f"I have a {animal} named {name}.")

describe_pet("dog", "Buddy")        # Positional arguments

describe_pet(animal="cat", name="Mittens")  # Keyword arguments

describe_pet("hamster")              # Uses default for name

Quiz Question 3

Question: What happens if you call a function without providing a required positional argument?

  • A) The function uses a default value
  • B) Python raises an error
  • C) The function skips that parameter
  • D) The function returns None

How Functions Return Values

So, you’ve given your function some information—now what? Sometimes, you want your function to give something back. This is where return values come in.

A return value is the result a function sends back after it finishes its work. In Python, you use the return statement to give this value back.

For example:

def add(a, b):
    return a + b

When you call add(2, 3), the function returns the value 5. You can save this value in a variable:

result = add(2, 3)
print(result)  # This will print 5

Why are return values useful? They let you use the result of a function elsewhere in your program. Instead of just printing something, your function can send information back for you to use however you want.

If you don’t include a return statement, Python functions return None by default.


Quiz Question 4

Question: What happens if you do not include a return statement in your Python function?

  • A) The function will return 0
  • B) The function will return None
  • C) The function will cause an error
  • D) The function will return the last value calculated

The Role of def in Functions

Every function in Python starts with the word def. This tells Python you’re defining a new function.

When you write:

def say_hello(name):
    return "Hello, " + name + "!"
  • def starts the function definition.
  • name is the parameter (the placeholder for an argument).
  • The return statement gives back the result.

If you’re new to writing functions, remember:

  • Use def to define a function.
  • List parameters in parentheses after the function name.
  • Use return to send a value back.

Quiz Question 5

Question: Why do we use the keyword def in Python?

  • A) To delete a function
  • B) To define a new function
  • C) To display output
  • D) To return a value

Why Arguments and Return Values Matter

Understanding python function arguments and return values is more than just a technical skill—it’s a way to make your code smarter and more adaptable.

Imagine you’re writing a program to calculate the total price of items in a shopping cart. With arguments, you can pass in different prices and quantities. With return values, your function can give you the total cost, which you can use for receipts, discounts, or anything else.

Here are some everyday tasks made easier with functions:

  • Calculating grades based on scores (arguments: scores; return value: grade)
  • Sending personalized messages (arguments: name, message; return value: formatted message)
  • Converting temperatures (arguments: temperature; return value: converted value)

The more you practice, the more confident you’ll become in using these building blocks for bigger projects—like web apps, games, or data analysis.


Check Your Understanding

Ready to see how much you’ve learned? Try these quick questions:

  1. What’s the difference between a parameter and an argument in Python?
  2. Why would you use a return value instead of just printing from a function?
  3. Write a simple function that takes two numbers as arguments and returns their product.

Take a moment to answer these questions. If you’re not sure, review the examples above and try writing your own functions!


Keep Practicing!

Learning how to use python function arguments and return values is a key step in your programming journey. These concepts let you write code that’s flexible, reusable, and ready for real-world challenges.

Keep experimenting with your own functions. Try passing in different arguments and using return values in creative ways. With each step, you’ll get closer to building the kinds of programs you dream about.

Happy coding!


Quiz Answer Key

Question 1

Correct answer: A) To allow the function to accept different input values each time it is called

Explanation: Parameters are placeholders in the function definition that let you pass in different arguments (values) when you call the function, making it flexible and reusable.


Question 2

Correct answer: B) Parameters are used in the function definition; arguments are the values passed when calling the function

Explanation: Parameters are the variable names listed in the function definition. Arguments are the actual values you provide when you call the function.


Question 3

Correct answer: B) Python raises an error

Explanation: If you call a function without providing a required positional argument, Python will raise a TypeError.


Question 4

Correct answer: B) The function will return None

Explanation: If you do not include a return statement, Python functions return None by default.


Question 5

Correct answer: B) To define a new function

Explanation: The keyword def is used to define a new function in Python.

Practical resource

Want a more structured Python path?

Use the Python Starter Pack to turn scattered tutorials into a focused practice path.

View the bundle
Coming soon

Python Starter Pack

A compact LearnPyFast PDF pack covering what Python is, installation, your first program, running Python code, and Python versions.

$9
PDF BundleTopic PackPythonBeginner
  • 5 curated chapters
  • Enhanced PDF edition with bundle-only learning guidance
  • Offline-friendly format for focused review
  • Source article links for future online updates

Coming soon

Related sites

Continue beyond Python

Explore related Worldmonger sites when you want to move from Python basics into JavaScript or LLM application building.

JavaScript tutorialstutorial

LearnJSFast

Beginner-friendly JavaScript tutorials for practical web development and self-taught developers.

JavaScriptFrontendWeb development
Visit LearnJSFast
LLM tutorialstutorial

LearnLLMFast

Practical LLM tutorials for builders who want to understand prompting, workflows, agents, and AI applications.

LLMAIBuilders
Visit LearnLLMFast

Keep learning

Related tutorials

Continue with nearby Python topics and beginner-friendly explanations.

beginner8 min read

Defining Functions in Python

Are you tired of writing the same lines of code over and over? Do you wish there was an easier way to organize your programs and make them easier to read?…

Read tutorial
beginner8 min read

Importing Modules in Python

Learning Python is like opening a toolbox full of useful gadgets. Many of these gadgets are called modules. If you want to write real programs,…

Read tutorial
beginner8 min read

Practice Exercises: Functions

Ready to build your Python skills? If you’ve learned how to define and use functions, now’s the perfect time to practice! Working through hands-on…

Read tutorial