Sunday, October 25, 2020

Functions in Python

A function is a block of code that does a specific task. Large programs are broken to functions to perform a particular task. Functions are executed when it is called with in a program. Functions take input data using arguments and returns a result. Now let us how to define functions and use in python

Functions in python are defined using the 'def' keyword followed by function name and arguments to the function and a colon to start a new block.

def functionName(arguments):

return [expression] is used to return a value from the function.


Python program uses indentation to start a new block. A indentation of 4 spaces is generally used to form the block of statements.

To break from a function use return with no expression, this breaks and exits from the function.


return with no expression returns 'None' , Capture the return of function into a variable and check.

Download the code from GitHub

No comments:

Post a Comment

Operations on Python Dictionaries