Skip to content
AgileLogics
4 min read

Functions

Prerequisites: Variables

A function is a reusable, named block of code that performs a specific task — written once, called as many times as needed.

Syntax

def function_name(parameter):
    ...

Example

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

greet("Ada")
greet("Grace")

Expected output

Hello, Ada!
Hello, Grace!

Common mistakes

  • Forgetting the parentheses when calling a function — greet refers to the function itself, greet("Ada") actually runs it.