Python Function.. Parameter, Arguments,Factorial of number.
Function:
It is difficult to maintain large scale program and the identification of the programming gets harder. The best way to create programming application is to divide a big program in small module and repeatedly call this module within program with the help of function and entire program can be devide into small independent modules.
A function is the self contained block of one or more statement that perform a special task when called. This improve the code readability as well as flow of execution and small modules can be managed easily.
Syntax:
the syntax for the python contains header and the body. The function header begins with the header 'def' followed by the function name and arguments are optional. the body contents the statement to be executed and function will be executed only when it is being called.
Example:
Write a python program to display a simple message
Source code:
Output:
Function use:
The functions are used for code reusability in program. Assume that a program is written for printing the number starting from 1-5,20-25 and 90-95
Output:
Parameter and Argument in Function:
Parameters are used to give input to the function in programs. They are specified with the pair of parenthesis in function ddefinition. When program calls a function, the values are also passed with the function.
While parameter are defined by name, arguments are value actually passed to a function when calling it. Thus parameter define what type of arguments a function can except.
Example:
Write a python program to find the factorial of a number.
Output:
Comments
Post a Comment