Function and Return Statement in Python, learn python from start

Function and Return Statement in Python 


Function: -

The function allows us to encapsulate code and reuse it throughout our programs.

Return Statements: -

Allow us to return values from functions back to the calling code.



A technique to organize a group of instructions into a reusable piece of code is to use functions. They can be called several times from various places in a program and are made to carry out particular duties. In Python, functions are defined by using the def keyword, followed by the function's name and, if applicable, any parameters. The following are the fundamental syntax for defining a function in Python. 

Example::1

Creating a Function to Add Two Values and Returning the Result in Python

Code



Output
                                               result = 33                                             

Example::2

Creating a Function to calculate the area of a circle in Python

Code



Output



Example::3

A function that returns a list of even numbers from a given list

Code




Output: -

[2, 6, 8, 18, 6, 2, 64, 2]





Subscribe to YouTube Channel AI with Faseeh
Follow on Facebook use this one AI with Faseeh

Comments