
Functions are one of the most important concepts in Python. They help you organize code into reusable blocks, making programs cleaner, shorter, and easier to manage.
What is a Function in Python?
A function is a block of code that performs a specific task. Instead of writing the same code multiple times, you can create a function once and use it whenever needed.

Image
image:wht is the use of function
image source:Geeksforgeeks
Example

Image
Here:
Why Use Functions?
Functions provide many advantages in programming.
Benefits of Functions

Image
image:syntax of the function
source: GeeksForGeeks
Creating a Function
In Python, functions are created using the def keyword.
Syntax

Image
Calling a Function
A function only runs when it is called.
Example

Image
Function with Parameters
Parameters allow functions to accept input values.

Image
Arguments are values passed to a function when it is called. They allow functions to receive input data and perform operations using those values.
Syntax
def function_name(arguments): # function body return value
Function with Multiple Parameters
You can pass multiple values into a function.
Example
def add(a, b):
print(a + b)
add(5, 3)
Output
8
Return Statement in Functions
The return keyword sends a value back from the function.

Image
Difference Between print() and return
Using print()
def add(a, b):
print(a + b)
Using return
def add(a, b):
return a + b
Types of Functions in Python
Built-in Functions
Python already provides many ready-made functions.
Examples
print()
len()
type()
input()
User-defined Functions
Functions created by programmers are called user-defined functions.
Example
def multiply(a, b):
return a * b
1. Default argument: Default argument use a predefined value when no value is passed during the function call.

Image
Keyword Arguments
pass values using parameter names, so argument order does not matter.
example shown below

Image
Local Variables

Image
Here:
Global Variables
Example:

Image
Here:
Positional Arguments: values are assigned to parameters based on their order in the function call.
example:

Image
Function within Functions
A function defined inside another function is called an inner function (or nested function). It is used to organize related logic and access variables from the outer function.

Image
Pass by Reference and Pass by Value
🔹 First, the big picture
🔹 Mutable vs Immutable
Key Concept: "Pass-by-object-reference"
🧠 Analogy
Think of variables as name tags pointing to boxes:
Python Lambda Functions

Image
🔹 What is a Lambda Function?
A lambda functionis just a small, anonymous function— meaning it has no name.It’s used when you need a quick, one-line function for short tasks.
Think of it like a shortcut: instead of writing a full defblock, you write a one-liner.
Syntax
python
lambda arguments: expression

Image
Multiple arguments

Image
Recursive Functions
A recursive function calls itself repeatedly until a condition is met.
Example

Image
Common Errors in Functions
Forgetting Parentheses
greet
Correct:
greet()
Missing Return Statement
def add(a, b): a + b
Correct:
def add(a, b): return a + b
Conclusion
Python functions help make programs modular, reusable, and easier to understand. By learning how to create, call, and use functions effectively, you can write cleaner and more professional Python code.
previous episode: Python Loops Explained | For Loop and While Loop | AIML EP-4 | CHiPSET Tech Articles | CHIPSET SRM University Ramapuram
Written by Chakradhar on May 25, 2026
