Skip to content
beginner

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…

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

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 exercises is one of the best ways to master programming concepts. These beginner-friendly Python function exercises will help you gain confidence, improve your problem-solving abilities, and set a strong foundation for your coding journey.


Why Practice Python Functions?

Functions are essential building blocks in Python. They let you organize your code, avoid repeating yourself, and solve problems step by step. Practicing functions will help you:

  • Break big problems into smaller, manageable parts.
  • Write code that’s easier to read and maintain.
  • Build confidence as you see your programs work.

Every programmer starts with simple exercises like these. The more you practice, the more natural it will feel to use functions in your own projects.


How to Approach These Exercises

To get the most from these Python beginner practice problems:

  • Read each problem carefully. Make sure you understand what the function should do.
  • Try solving it yourself first. Avoid looking up solutions right away.
  • Test your code with different inputs. This helps you spot mistakes and learn from them.
  • Embrace mistakes. Every error is a chance to learn and improve.

You’ll learn Python by doing, so let’s get started!


Beginner Python Function Exercises

Here are some Python function exercises designed for beginners. Each problem focuses on defining and using functions, working with arguments, and returning values. Try them in order—they get a bit more challenging as you go.

1. Greet Someone

Write a function called greet that takes a name as an argument and prints a greeting.

Example:
greet("Alice") should print:
Hello, Alice!


2. Add Two Numbers

Write a function called add_numbers that takes two numbers as arguments and returns their sum.

Example:
add_numbers(3, 5) should return 8.


3. Find the Square

Write a function called square that takes a number and returns its square.

Example:
square(4) should return 16.


4. Check Even or Odd

Write a function called is_even that takes a number and returns True if it’s even, and False if it’s odd.

Example:
is_even(7) should return False.


5. Repeat a Message

Write a function called repeat_message that takes a message and a number, and prints the message that many times.

Example:
repeat_message("Hi!", 3) should print:

Hi!
Hi!
Hi!

6. Get the First Character

Write a function called first_char that takes a string and returns its first character.

Example:
first_char("Python") should return 'P'.


7. Find the Maximum

Write a function called find_max that takes two numbers and returns the larger one.

Example:
find_max(10, 20) should return 20.


8. Calculate the Area of a Rectangle

Write a function called rectangle_area that takes the width and height of a rectangle and returns its area.

Example:
rectangle_area(5, 3) should return 15.


9. Count Vowels

Write a function called count_vowels that takes a string and returns the number of vowels (a, e, i, o, u) in it.

Example:
count_vowels("hello") should return 2.


10. Reverse a String

Write a function called reverse_string that takes a string and returns it reversed.

Example:
reverse_string("Python") should return "nohtyP".


Common Questions About Functions

What’s the difference between printing a value and returning a value from a function?
Printing shows a value on the screen. Returning sends a value back to where the function was called, so it can be used or stored.

Diagram showing the steps of defining a Python function, calling it with arguments, and returning a value to the caller.

This diagram illustrates how a Python function is defined, called with arguments, and how it returns a value to the caller. It helps clarify the difference between printing and returning, which is a common beginner confusion.

When should I use print and when should I use return?
Use print to display something for the user. Use return when you want to send a result back for further use in your program.

Can a function take more than one argument?
Yes! List multiple arguments in the parentheses when defining your function.

What happens if I call a function without all the required arguments?
Python will give you an error. Make sure to provide all required arguments unless your function has default values.

How do I test if my function works with different inputs?
Call your function with various inputs and check if the results are what you expect.

If a function doesn’t have a return statement, what does it return by default?
It returns None.

Can a function return more than one value?
Yes! You can return multiple values separated by commas. Python will package them into a tuple.

How do I write a function that repeats an action multiple times?
Use a loop (like for or while) inside your function to repeat the action.

What should I do if my function isn’t working as expected?
Check for typos, print out values to debug, and test with different inputs. Mistakes are normal and help you learn!

Is it okay to use the same function name for different functions?
No. Each function name should be unique in your program, or the latest definition will overwrite the previous one.


Practice Quiz: Test Your Function Skills

Check your understanding with this quick quiz! Write your answers on paper or in your code editor.

Quiz Question 1

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

  • A) To store data
  • B) To perform a specific task or calculation
  • C) To print text only

Quiz Question 2

Question: What keyword do you use to define a function in Python?

  • A) define
  • B) function
  • C) def

Quiz Question 3

Question: What will add_numbers(2, 3) return if you wrote the function correctly?

  • A) 5
  • B) 6
  • C) 23

Quiz Question 4

Question: True or False: A function can return more than one value.

  • A) True
  • B) False

Quiz Question 5

Question: What does the return statement do in a Python function?

  • A) It prints a value to the screen.
  • B) It ends the function and sends a value back to where the function was called.
  • C) It defines the function's name.

Quiz Question 6

Question: Which of the following is a correct way to define a function that takes two arguments and returns their sum?

  • A) def add(a, b): return a + b
  • B) function add(a, b): return a + b
  • C) def add(a, b): print(a + b)

Quiz Question 7

Question: Write a function that takes a number and returns True if it is negative, and False otherwise.


Next Steps After Practicing Functions

Great job working through these Python function problems! Here’s how you can keep building your skills:

  • Explore more advanced function topics. Learn about default arguments, keyword arguments, and variable-length arguments.
  • Start using functions in small projects. Try building a calculator, a simple game, or a text-based menu.
  • Learn about modules and code organization. Discover how to group your functions into separate files and reuse your code.

The best way to learn Python is by doing. Keep practicing, experimenting, and challenging yourself with new problems. Every function you write brings you closer to your programming goals!


Keep Going!

Becoming a confident programmer takes time and practice. Celebrate your progress and don’t be afraid of mistakes—they are stepping stones to success. Keep working on Python function exercises, explore new challenges, and enjoy the journey. You’re on your way to mastering Python and opening doors to exciting programming opportunities!


Quiz Answer Key

Question 1

Correct answer: B) To perform a specific task or calculation

Explanation: Functions are used to organize code and perform specific tasks or calculations.


Question 2

Correct answer: C) def

Explanation: In Python, you define a function using the def keyword.


Question 3

Correct answer: A) 5

Explanation: If add_numbers is written correctly, add_numbers(2, 3) returns the sum, which is 5.


Question 4

Correct answer: A) True

Explanation: Functions can return more than one value by separating them with commas; Python returns them as a tuple.


Question 5

Correct answer: B) It ends the function and sends a value back to where the function was called.

Explanation: The return statement exits the function and provides a value to the caller.


Question 6

Correct answer: A) def add(a, b): return a + b

Explanation: This is the correct Python syntax for defining a function that takes two arguments and returns their sum.


Question 7

Correct answer:
A function that takes a number and returns True if it is negative, and False otherwise:

def is_negative(num):
    return num < 0

Explanation: This function checks if the number is less than zero and returns the appropriate Boolean value.

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