This tool is donation based and free. 🙏 We're looking for donations to keep it running — $360/year covers our server costs.

$18 of $360 · 5%
Donate
This fact check is over 3 months old. The situation may have changed significantly — please recheck before relying on it.

What does def do in Python

“What does def do python”
Defines a function
Confidence: High Checked on May 11, 2026

Summary

In Python, the `def` keyword is used to create (define) a new function. It introduces a reusable block of code that can accept arguments, perform operations, and optionally return a result. This is the fundamental way to declare functions in Python.

Recheck this fact Runs a fresh check with up-to-date sources

Sources 60 searched

lancaster.ac.uk
  • Python functions - PHYS281

    **kwargs must be the final argument in your function definition, but you can have other positional and explicit keyword arguments before it. Within the function kwargs (without the preceding two asterisks) is just a Python dictionary containing the keywords and their values as key-value pairs. If you know that you are only ever going to pass the additional keywords "firstname" and "lastname" to anotherfunc then you could do: def anotherfunc(message="Hello", **kwargs): print(kwargs) # print statement is just for show here # use somefunc output = somefunc(**kwargs) return f"{message} {output}" print(anotherfunc(firstname="Matt", lastname="Pitkin")) {'lastname': 'Pitkin', 'firstname': 'Matt'} Hello Matt Pitkin

sites.pitt.edu
  • Python 3 Notes: User Defined Functions

    Python 3 Notes [ HOME | LING 1330/2330 ] User-Defined Functions << Previous Note Next Note >> On this page: def, return, docstrings, help(), value-returning vs. void functions Functions: the Basics Let's bust out some old-school algebra. You learned "functions" as something like: f(x) = x2 ...

geeksforgeeks.org
coderivers.org
  • Python `def`: A Comprehensive Guide - CodeRivers

    It takes some input (arguments), performs operations on that input, and may return an output. For example, you can have a function that calculates the square of a number or a function that prints a welcome message. The basic syntax for defining a function in Python using def is as follows: ...

w3schools.com
  • Python def Keyword

    Python Overview Python Built-in ... Interview Q&A Python Bootcamp Python Training ... The def keyword is used to create, (or define) a function....

realpython.com
  • def | Python Keywords – Real Python

    In Python, the def keyword defines a function, which is a reusable block of code that can accept data input, perform a specific computation or task, and return a result or produce a side effect.

codecademy.com
medium.com
funtech.co.uk

This fact check is free and donation-based. $1 powers ~30 fact-checks.

Donate $1 to support fact-checking

Check another fact