Function (def)

A named block of reusable code, defined with def; it can take arguments and return a value.

Also called: def, return, arguments, default argument

Domain
Languages
Type
Term
Source
General
Language
Python

Example

The function slugify turns "Hello Bali" into "hello-bali".

In code

def slugify(text: str, sep: str = "-") -> str:
    return sep.join(text.lower().split())

slugify("Hello Bali")             # 'hello-bali'
slugify("Hello Bali", sep="_")    # keyword argument

Learn more

Related terms

Added 2026-11-30 · Last reviewed 2026-11-30