A block of code that is executed when it is called is defined as a function. Keyword def is used to define a Python function.