Defining and Calling Functions

Functions in Python allow you to group code into reusable blocks. You define a function using the def keyword.

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

greet("Alice")  # Output: Hello, Alice!

Functions help make your code modular, readable, and easier to debug.

Next →