Python Tutorial in Hindi #13 - Functions

In this video by Mohit Decodes, you’ll learn everything about Functions in Python – from how to define and call functions to using parameters, return values, and default arguments. This is one of the most important concepts in Python for clean and reusable code.


✅ Topics Covered:

What is a Function in Python?

How to Define and Call a Function

Functions with Parameters

Return Statement & Returning Multiple Values

Default Parameters with Examples

Best Practices for Using Functions


# Python Tutorial #13 – Functions
# Author: Mohit Decodes

# ------------------------------
# 🧩 Example 1: Simple Function
# ------------------------------
def greet():
print("Hello! Welcome to Mohit Decodes")

# function call
greet()

# ------------------------------
# 🧩 Example 2: Function with Parameters
# ------------------------------
def add(a, b):
print("Sum is:", a + b)

add(5, 10)
add(20, 25)

# ------------------------------
# 🧩 Example 3: Function with Return Value
# ------------------------------
def multiply(x, y):
return x * y

result = multiply(4, 6)
print("Multiplication result:", result)

# ------------------------------
# 🧩 Example 4: Returning Multiple Values
# ------------------------------
def calc(a, b):
add = a + b
sub = a - b
mul = a * b
div = a / b
return add, sub, mul, div

res = calc(10, 5)
print("Addition:", res[0])
print("Subtraction:", res[1])
print("Multiplication:", res[2])
print("Division:", res[3])

# ------------------------------
# 🧩 Example 5: Default Parameters
# ------------------------------
def greet_user(name="Guest"):
print("Hello", name)

greet_user("Mohit")
greet_user()

# ------------------------------
# 🧩 Example 6: Keyword Arguments
# ------------------------------
def student(name, age):
print("Student Name:", name)
print("Age:", age)

student(age=21, name="Ravi")

# ------------------------------
# 🧩 Example 7: Function Calling Another Function
# ------------------------------
def welcome(name):
print("Welcome", name)

def process():
print("Processing...")
welcome("Mohit Decodes")

process()

# ------------------------------
# 🧩 Example 8: Nested Function
# ------------------------------
def outer():
print("Outer function started")

def inner():
print("Inner function executed")

inner()
print("Outer function ended")

outer()

# ------------------------------
# 🧩 Example 9: Function with Variable Number of Arguments (*args)
# ------------------------------
def show(*names):
for n in names:
print("Hello", n)

show("Mohit", "Ravi", "Amit")

# ------------------------------
# 🧩 Example 10: Function with Keyword Arguments (**kwargs)
# ------------------------------
def details(**info):
for key, value in info.items():
print(key, ":", value)

details(name="Mohit", age=30, city="Delhi")

# ------------------------------
# 🧩 Example 11: Combining Parameters
# ------------------------------
def mix(a, b=10, *args, **kwargs):
print("a:", a)
print("b:", b)
print("args:", args)
print("kwargs:", kwargs)

mix(5, 15, 20, 25, x=50, y=100)

# ------------------------------
# 🧩 Example 12: Function Documentation (Docstring)
# ------------------------------
def square(num):
"""This function returns the square of a number."""
return num ** 2

print(square.__doc__)
print("Square of 7:", square(7))