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.

Correct Def Syntax in Python

“How do I write a correct def python”
Correct def syntax
Confidence: High Checked on May 11, 2026

Summary

Write a function by starting with the `def` keyword, followed by the function name, parentheses containing any parameters, and a colon. Place the function body on the next line(s) indented consistently (typically four spaces). End the function with an optional `return` statement to output a value.

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

Sources 60 searched

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 ...

cs.stanford.edu
  • Python Functions

    Here is an example Python function named "foo". This function doesn't do anything sensible, just shows the syntax of a function. ... name - def is followed by the function's name, here foo The name is chosen by the programer to reflect what the function does Here "foo" is just a CS nonsense word

anh.cs.luc.edu
educative.io
geeksforgeeks.org
  • Python def Keyword - GeeksforGeeks

    ... def fun(n): x = 2 count = 0 while count < n: for d in range(2, int(x ** 0.5) + 1): if x % d == 0: break else: print(x) count += 1 x += 1 n = 10 fun(n) ... In Python, functions are first-class objects, which means you can pass functions as ...

  • Python Functions - GeeksforGeeks

    def function_name(arguments): # function body return value

peps.python.org
freecodecamp.org
w3schools.com
  • Python Functions

    The code inside the function must be indented. Python uses indentation to define code blocks. To call a function, write its name followed by parentheses: def my_function(): print("Hello from a function") my_function() Try it Yourself »

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

Donate $1 to support fact-checking

Check another fact