Skip to content

Python Function

Syntax

A function in Python can be defined using the def keyword, followed by the function name, parentheses, and a block of code.

def function_name():
# Code to execute
# Call function
function_name()

Example

def greet():
print("Hello World")
greet()
# Output: Hello World