Chapters
Python114 chapters

ReferenceKeywords

def

Defines a function. The body runs only when the function is called.

Signature

def name(parameters):

Returns

Nothing; it binds the name to a function object.

Example

Python
def double(n):
    return n * 2

print(double(5))
print(type(double).__name__)

Output

10
function

See also