Python – Functions:

There are 2 types of functions.

  1. User-defined functions
  2. Pre-defined functions

User-Defined functions:

In Python, User-defined function is a block of code which can reusable. Once they are defined or written, that can be used multiple times and in other applications too.

Generally, the syntax of user-defined functions is represented by keyword def. Below is the syntax for defining the function without arguments.


Let us create a Function for returning a value of x after processing a loop.

Let us call the User-defined Function:

Using the argument value as 20:

Using the argument value as 50:

Pre-defined Functions:

Pre-defined functions are already existing functions which cannot be changed. But still we can make our own custom functions using those pre-defined functions.