Functions in Python
Functions are a block of code which can perform a
specific the task over the data passed into it.
The function in python can also be said as subprogram.
The function can provide the high degree of code
reusing.
In Python, we have 3 types of functions:-
1. Built-in
2. Module defined
3. User defined
Built In functions
Built In functions in python are the functions which can
be used while writing the code/program without
importing any library.
Ex print() , input() , list() , tuple() etc.
Module defined functions
To use Module defined functions, programmer need to
import a specific library in python environment and use
the functions present in it.
Ex
Using dot (.) operator we can access see the list of
functions present in the module.
User defined functions
User defined are those functions which are defined by
the programmer i.e. their functionality is defined by
the programmer.
These are created using “ def ” keyword the def stands
for definition.
Example :
Syntax:
Practice questions:-
Q1 Import math module and use any one function.
Q2 Import random module and use any one function.
Q3 Create a user defined function calculating sum,
cube, square using below example.