HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Glossary
  2. /Python and data
  3. /Function (in Python)

What is Function (in Python)?

In short

A function is a named block of code that does one job. You give it inputs, called arguments, and it can give back a result with return. It is sometimes compared to a recipe that you can use again and again.

In simple words

A function is defined with def. It lets you write a piece of code once and use it many times, which avoids repeating yourself and makes mistakes easier to find. Variables created inside a function exist only inside it. If a function has no return, it gives back None.

Example

This prints 9.0, which is 12×2.0×3.02\tfrac{1}{2} \times 2.0 \times 3.0^221​×2.0×3.02 joules.

Also searched as: recipe python meaning, meaning recipe python, python recipe definition, python definition recipe, python inverse function.

Learn it properly

  • Lessons on this topic
  • Test yourself

Related terms

  • Variable (in Python)
  • Recursion
  • Class and Special Methods (in Python)

← All glossary terms

Learn it in

  1. Functions: Name a Recipe
All lessons on this topic →

Practise

  1. A function ticket_price(age) gives the price of a museum ticket: under 5 is free (0)…Medium
  2. Same name, two variablesMedium
  3. This program should show The total is 50. It stops with an error. Find the fault and fix…Medium
  4. Which of these four programs shows something? Say it before you run each one.Easy

Quick questions

  1. A function changes a list that it receives, and then builds a new list with the same…Hard
  2. A function has two parameters with default values. Which calls return 20? Choose every…Hard
  3. A function has two parameters with default values, and it returns from three different…Hard

More Python and data terms

  1. Cell (in a Python notebook)
  2. Dictionary (in Python)
  3. For Loop
  4. If Statement (in Python)
  5. Import (Python modules and libraries)
  6. List (in Python)
All Python and data terms →

Try it yourself

Python labs run in your browser. Type the code, run it and see what happens.

Open a Python lab