Python Functions

Functions in Python

Introduction

A function is a block of code which only runs when it is called. You can pass data, known as parameters, into a function.

A function can return data as a result.

Creating a function

In Python, a function is defined using the def keyword.

Example

Calling a function

The function is called by using the function name followed by parentheses.

Example

Arguments

Information can be passed into functions as arguments. Arguments are specified inside the parentheses. You can add as many arguments as you want, just separate them with a comma.

Example

Output