Skip to content

4.1.1 Function Definition (def)

In Python, functions are defined using the def keyword.
A function definition creates a reusable piece of code that can be called multiple times.


Function Structure

A function definition includes:

  • The def keyword
  • A function name
  • Parentheses for parameters
  • An indented block of code

The function body contains the statements executed when the function is called.


Function Naming

  • Function names should use snake_case
  • Names should clearly describe the function’s purpose
  • Python keywords must not be used as function names

📌 Note:
Well-named functions improve code readability and maintainability.