SSITSMentor - CS IP Tasks
12/02/2023
New Batch For Python course is starting soon
30/04/2022
Python Function Defination -
Function is used for code reusability.When you want to do something repeatedly, you can define that as a function and call that function whenever you need in further in that script.
Python Function Syntax
Syntax to define a function in Python:
def function_name(parameters):
# Function Defination
return result
* Use def keyword to define function, give your function a name, followed by a pair of parentheses, and end the line with a colon (:).
* If your function takes arguments, the names of the arguments (parameters) are mentioned inside the opening and closing parentheses.
* In function definition, the arguments that your function consumes are referred to as parameters.
* When you call the function with specific values for these parameters, they're called arguments or actual parameters. This is because the arguments in the function call are the values used for the function's parameters.
* Then, you begin an indented block. This is the body of the function that describes what your function does.
* Return statement that returns the result of the operation on the arguments. The return statement returns control to the point where the function was originally called.
( Note that the arguments and the return statement are optional. This means that you could have a function that takes in no arguments, and returns nothing. )
How to Create a Simple Function in Python
Simple function in Python that greets the user:
=>
def my_func():
print("Hello!")
-----------------------------------------------------------
Click here to claim your Sponsored Listing.
Category
Address
Annapurna And MG Road Indore
Indore