def( ) & Return function in python

Share:

Def Function:

def is short for “define”. It's a keyword that you need to define a function. All the code that you put between the def function_name(parameters) and end will be executed every time you call the function_name later.

for example we define a function as a name of ghost
def ghost():                                                                       
    print("Did you know python have a incredible ghost?")
                                                                                         
print(ghost)                                                                       
 output:                                                                            
Did you know python have a incredible ghost? 
Note: if we don't write the print ghost it can not print any thing

 program 2

To print  the function we must want to call the function. 
To call the function we want to write print(function name).
In def ghost(): the ghost is the function name .
It is most important to write parentheses( ) & Semicolon: after write the function name because without these your function is not defined.
Here is 1 more  program of def ( ) function:
def abc():
	x = 10
	print("Value inside function: ",x)

x = 20
abc()
print("Value outside function: ",x)

Output:

Value inside function: 10
Value outside function: 20

Return Function():

The Python return statement is a special statement that you can use inside a function or method to send the function's result back to the caller. A return statement consists of the return keyword followed by an optional return value.

The return statement causes your function to exit and hand back a value to its caller. The return statement is used when a function is ready to return a value to its caller.