Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 3 — Functions: Defining, Calling, Types

Lesson 34 of 50 in the free Python Programming notes on Siksha Sarovar, written by Rohit Jangra.

Concept of Functions

A function is a reusable, named block of code that performs a specific task.

Defining and Calling a Function

def greet():
    print("Hello, Welcome to Python!")

greet()      # function call
greet()      # can be called multiple times

Syntax

def function_name(parameters):
    """optional docstring"""
    statement(s)
    return value   # optional

Types of Functions

1. Built-in functions — provided by Python itself.

print(len("hello"))    # len() is built-in
print(max(3, 7, 2))     # max() is built-in

2. User-defined functions — written by the programmer.

def square(n):
    return n * n

print(square(5))   # 25

3. Lambda (anonymous) functions — small, single-expression functions defined with lambda.

square = lambda n: n * n
print(square(6))   # 36

add = lambda a, b: a + b
print(add(3, 4))    # 7

Function with no return (returns None implicitly)

def show_message():
    print("This function returns nothing")

result = show_message()
print(result)   # None

Why use functions?

  • Reusability — write once, call many times.
  • Modularity — break a large problem into smaller pieces.
  • Readability — named functions document intent.
  • Easier debugging and testing — isolate logic in small units.

Flowchart of a function call