codeGK
Code it ALL
Python Function - CodeGK
♦ Python Function

♣ About Python Function

A Function is a block of code which runs when associated Function is invoked.
A Function can accept parameters and accordingly process the algorithm.
After processing of algorithm, a Function may Return a value(a particular combination of Data Types).
A Function can be of two types in-built and user-defined.
in-built Function comes pre-defined with the Python Language package, for example, len() is a function to calculate the length of any sequential object.
A user-defined Function is defined by the user and is customizable.

♣ Example1: Python Function to add two numbers or strings

In this example, sum of two numbers is calculated using a function.
Example
Input:
Output:

♣ Example2: Recursive Function to calculate factorial in Python

In this example, factorial of a number is calculated using recursive function calls.
Example
Input:
Output:
Prev_LessonNext_Lesson