Labs ICT
โญ Pro Login

Functions

1 min read | Python Tutorial
โญ

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

What is a Function?

A function is a reusable block of code that performs a specific task. You define it once with def and call it whenever you need it.

Basic Function

def greet(name):
    return "Hello, " + name + "!"

print(greet("Alice"))

Function with Return Value

Use return to send a result back to the caller.

def add(a, b):
    return a + b

result = add(5, 3)
print(result)

Docstrings

A docstring describes what the function does. It goes right after the def line.

def square(n):
    """Return the square of a number."""
    return n * n

print(square(4))
print(square.__doc__)

๐Ÿงช Quick Quiz

What keyword defines a function in Python?