def

The Python keyword that starts a function definition: def, the name, parameters in parentheses, a colon, then an indented body.

In more detail

Running a def only remembers the function under its name; the body runs later, each time the function is called. The indented lines beneath the heading are the body, and the first unindented line ends it.

Example

def greet(name):
    print("Hello", name)

Related terms

Taught in

References

Certification courses