Python Function
Python Function- Write Once, Use Many Times Introduction Imagine you need to calculate the sum of two numbers many times in your programs with different values. Will you write the code again and again? No. Instead, you create a function in a program, that can have arguments, if needed can perform certain functionality can return a result What is a Function? A function is a block of code that performs a specific task. In Python we create functions using the def keyword. Basic Function Syntax def function_name(): #code Example: def calcSomething (x): r=2* x**2 return r a= int(input("Enter a number:")) print(calcSomething(a)) 1. Where x is the argument to function calcSomething 2. return statement returns the computed result. 3. calcSomething(a) calls the function. Calling/Invoking/Using a Function To use a function that has been defined earlier, you need to write a function call statement in Python. A function call statement takes the following form: ...