Advantage of Functions


Advantage of Functions

  • Using functions, we can avoid rewriting the same code repetitively and thereby, increasing the efficiency of the code.
  • We can call numerous times Python functions in a program and anywhere in a code.
  • We can track a large Python program effortlessly when it is divided into multiple uncomplicated functions.
  • Reusability is the main achievement of accessing Python functions hassle-free.
  • Function calling is always overhead in the Python code

NOTE:- A function must be defined by calling the function; otherwise, the Python interpreter would give an error.

NOTE- It's an optional string that is used to briefly explain what a function is working for.

  • The return statement is used to return a particular value from a function and go back to the place from where it was called.
  • If no return statement is present inside a function, then the function will return the None object.

Example:

def my_function(fname): print(fname + " website") my_function("1knowledge2life ") my_function("2knowledge2life ") my_function("3knowledge2life ")

OUTPUT:

1knowledge2life website
2knowledge2life website
3knowledge2life website