0% found this document useful (0 votes)
14 views11 pages

Functions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views11 pages

Functions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Functions

Function

What is Function?
o Python function is a block of statements that return the specific task.
o The idea is to put some commonly done tasks together and make a
function so that instead of writing the same code again and again for
different inputs, we can do the function calls to reuse code contained
in it over and over again.
Benefits of using functions:
 Increase code Readability
 Increase code Reusability
Function

Python Function Declaration:


Function

Types of function:
Built – in – function:
o These are standard functions in python that are available to use.
o For Example: append(), clear(), add() etc..
User – defined – function:
o We can create our own functions based on our requirements.
Function

Creating a Function:
o We can create a user defined function in python by using the def
keyword.
o After creating a function we can call it by using the name of the
function followed by parenthesis containing parameters of that
particular function.
Example: Output:
Function

Python function with arguments:


o An argument is a value that is accepted by a function.
o If we create a function with arguments, we need to pass the
corresponding values while calling them.
Example: Output:
Function

Return statement:
o If we want our function to return some value to a function call we can
use return statement.

o The return statement also denotes that the function has ended. Any
code after return is not executed.

o A python function may or may not return a value.


Function

Example: Output:
Function

Standard functions:
o Standard library functions are the built-in functions that can be used
directly in our program.

o These library functions are defined inside a module and to use them,
we must include the module inside our program.
Function

Example: Output:
Thank You

You might also like