Hello programmers! Have you ever seen some fruitful things in programming languages? I guess not! So, let’s discuss today about FRUCTIFEROUS FUNCTIONS which are going to benefit you in many ways and are really worthy!
Defining any functions are the core of the protractile programming. Python allows mandatory arguments, keywords, etc, to be defined in a function.
WHAT ARE FRUCTIFEROUS FUNCTIONS?
Functions are basically blocks of code which performs certain particular sort of application or task as per given in code.
It makes our code reusable. Functions are required because they reduce the redundancy in our program and they increase the readability.
Basically, functions are divided into two following types:
These functions are built into python and they can be called directly.
These functions are made by Users and then they can be used and called anytime.
Let’s understand how to define a function in Python:
1. Function always begin with the keyword def and followed by parenthesis “()”.
2. You can input any type of arguments or parameters within the parenthesis.
3. The first statement of the function is optional. That means; it is docstring or documentation string which is a string literal.
4. The statements/code within the function are always indented and starts with a colon “:”.
5. At last; the return statement is written to return some value or expression.
Syntax: def name_of_function(any_no_of_parameters):
You all now might be thinking that after defining function, how we can use it in the program? Right?
Don’t worry! Let’s see that a function can be called after defining in the program.
How to call a function?
Once you have defined function, you can execute it in the program by calling it. You can directly call a function from python prompt or you can call it from another function. Let’s see an example of how to call a function: function.py
In this way, you can define and call a function easily in python and it can used as many times as you want. Let’s wrap it up to here. Tomorrow, we’ll further see that how to input various parameters, pass by value, pass by reference, etc. in a function. Practice it well! Have a great one, all!