Python Functions

python_with_shubham
python_with_shubham
June 27

PYTHON FUNCTIONS

Funtions:-

 A function is a block of organized, reusable code that is used to perform a single, related actions.

Defining a Function:- 

A function is created using def Keyword followed by parenthesis(def functionName()). The code block within every function starts with a colon (:) and is indented. 

syntax:-     

def functionname( parameters ):

Example:-    

Calling a Function:-

After defining a function name and specifies the parameters, we have to need call that function .

Example:-

Output:- This is a function

Return Statement in Python:- 

A return statement is used to end the execution of the function call and “returns” the result to the caller. The statements after the return statements are not executed.

Example:- 

return statement example
return statement example

Types of Functions

There are three types of functions in Python:-

                                      print(lambda_cube(5))

Output:-         125

Scope of Variables:-

The scope of a variable determines the portion of the program where you can access a particular identifier. There are two basic scopes of variables in Python-

1. Global variables- Variables that are defined outside a function body have a Global scope.

2. Local variables- Variables that are defined inside a function body have a Local scope.

***

Follow me on Instagram:-

                                                      Python_with_Shubham


Today's deal from platiplus

More from the author

Python Functions

Comments (1)

Add a Comment

Reply