Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

FUNCTIONS IN PYTHON

Types of Functions:
There are three types of functions in python:
1. Library Functions (Built in functions)
2. Functions defined in modules
3. User Defined Functions

1. Library Functions: These functions are already built in the python library.
For example: type( ), len( ), input( ) etc.

2. Functions defined in modules: These functions defined in particular modules.


When you want to use these functions in program, you have to import the
corresponding module of that function.
For example:
(a) Functions of math module
(b) Function in random module
*random module has function random ( ) , randint( ).

3 User Defined Functions: The functions those are defined by the user are called
user defined functions.
PARAMETERS
OR

FORMAL ARGUMENTS OF PYTHON

1.) Positional arguments


2.) Default arguments
3.) Keyword (or named ) arguments

1) Positional arguments
The values of arguments are matched with parameters position wise.

2) Default Arguments
A parameter having default value in the function header is known as a default
parameter.

3) Keyword (Named Arguments)


Specifying names for the values being passed in the function call is called keyword
arguments.

Q )What is the difference between parameters ( Formal Parameters )and arguments( Actual
Parameters)?

Parameters( Formal Parameters ) Arguments( Actual Parameters)


-Values provided in function header -Values provided in function call
Q) What are the different types of functions based on returning values?
There are two types of functions:

1) Functions returning some value (non void functions / fruitful functions)


2) Functions not returning any value ( void functions / non fruitful functions)

Q) Differentiate between Local variable and Global variable

Local Variable Global Variable


It is a variable declared within a It is a variable declared outside all
function or within a block. the functions

It is accessible only within a It is accessible throughout the


function / block in which it is program
declared.

Life time of a local variable is Life time of a global variable is


their function’s run. entire program run.

Function header:  the function header specifies the name of the function, and
any arguments (inputs, or parameters) into the function.

Return statement: The Python return statement is used to return a value from a


function. The user can only use the return statement in a function. It cannot be used
outside of the Python function. A return statement includes the return keyword and the
value that will be returned after that.

Global keyword: In Python, the global keyword is used to modify the


variable outside of the current scope. Global keyword is used inside a
function when the variable has to be updated using the variable’s initial
value.

You might also like