Which Python Keyword Defines a Function

Benjamin Jul 11, 2026

When it comes to defining functions in Python, there's a specific keyword that plays a crucial role. This keyword is not only essential for structuring your code but also for understanding Python's syntax and semantics. So, which keyword is it?

a table with words that are used to describe the keywords for each keyword
a table with words that are used to describe the keywords for each keyword

In Python, the keyword used to define a function is 'def'. This keyword is followed by the function name, parentheses, and a colon. Let's delve into this keyword and explore its usage in Python.

Keywords in python
Keywords in python

Understanding the 'def' Keyword

The 'def' keyword in Python is used to define a function. It's a reserved keyword, meaning it has a special meaning in Python and cannot be used as a variable or function name. When Python encounters 'def', it knows that a function definition is about to begin.

Minimalist Tech Workspace Ideas
Minimalist Tech Workspace Ideas

The basic syntax of a function definition in Python is as follows:

def function_name(parameters):

Here, 'function_name' is the name of the function, and 'parameters' are the inputs that the function expects.

Most Used Keywords in Python
Most Used Keywords in Python

Defining a Function

Let's create a simple function using the 'def' keyword. This function will greet the person whose name is passed as an argument.

def greet(name): print(f"Hello, {name}!")

In this example, 'greet' is the function name, and 'name' is the parameter. When we call this function with an argument, like 'greet("Alice")', it will print "Hello, Alice!".

Functions in Python | Types, Example
Functions in Python | Types, Example

Calling a Function

Now that we've defined a function, let's see how to call it. In Python, you call a function by using its name followed by parentheses. If the function expects arguments, you provide them inside the parentheses.

greet("Bob")

This will output: "Hello, Bob!"

Keywords in Python
Keywords in Python

Function Parameters and Arguments

Python functions can accept any number of arguments, and these arguments can have default values. Let's explore this with an example.

All Important Python Functions for Beginners (Complete Cheat Sheet)
All Important Python Functions for Beginners (Complete Cheat Sheet)
IMPORTANT FUNCTIONS IN PYTHON
IMPORTANT FUNCTIONS IN PYTHON
Coding For Beginners Python - Learn the Basics - Functions
Coding For Beginners Python - Learn the Basics - Functions
a computer screen showing the different types of commands and symbols for each type of device
a computer screen showing the different types of commands and symbols for each type of device
Functions
Functions
a poster with different types of text on it
a poster with different types of text on it
Python VS R Language
Python VS R Language
30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast
30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast
Python Keywords and Identifiers (Updated) | DigitalOcean
Python Keywords and Identifiers (Updated) | DigitalOcean
Imp💯 Python functions
Imp💯 Python functions
an important function in python is to display text or numbers and symbols on the table
an important function in python is to display text or numbers and symbols on the table
two black and gold posters with different types of wires on them, one in the middle
two black and gold posters with different types of wires on them, one in the middle
Master Python Functions – Write Smarter Code! 🐍✨
Master Python Functions – Write Smarter Code! 🐍✨
a poster with different types of text and numbers on the back ground, including words that are
a poster with different types of text and numbers on the back ground, including words that are
Python keyword-only arguments cheat sheet
Python keyword-only arguments cheat sheet
Shortcut to learn Python.[Cheatsheet]
Shortcut to learn Python.[Cheatsheet]
Python Cheatsheet
Python Cheatsheet
Coding For Beginners Python - Learn the Basics - Functions
Coding For Beginners Python - Learn the Basics - Functions
Python Cheat Sheet for Beginners
Python Cheat Sheet for Beginners
an important python functions chart with the words and numbers on it, including instructions to use them
an important python functions chart with the words and numbers on it, including instructions to use them

Optional Parameters

You can define a function with optional parameters by assigning a default value to the parameter. If an argument is not provided for this parameter when calling the function, the default value will be used.

def greet(name="World"): print(f"Hello, {name}!")

Here, if we call 'greet()', it will print "Hello, World!". But if we call 'greet("Alice")', it will print "Hello, Alice!".

Keyword Arguments

Python also supports keyword arguments, which allow you to specify the name of the argument along with its value. This can make your code more readable and easier to understand.

greet(name="Charlie")

This will output: "Hello, Charlie!"

In conclusion, the 'def' keyword is the backbone of function definition in Python. It's a powerful tool that allows you to create reusable, modular code. Whether you're a beginner or an experienced Python developer, understanding and mastering the use of 'def' is crucial for writing efficient and maintainable code. So, go ahead, start defining functions, and make your Python journey more productive and enjoyable!