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
Example::2
Creating a Function to calculate the area of a circle in Python
Code
Output
[2, 6, 8, 18, 6, 2, 64, 2]
Follow on Facebook use this one AI with Faseeh
Comments
Post a Comment