The function can be defined using the def. The syntax of function definition is as follows ‒
Defining
a Function
The
function can be defined using the def.
The syntax of function definition is
as follows ‒
def
function_name(parameters): //This colon
(:) is must
statements
Example
of creation of function
def test_fun():
print("This is
function Definition..")
The
first line of function definition is called function header and rest is called body.
Note
that ‒ The code within every function starts
with a colon (:) and should be indented (space).
Python
functions don't have any explicit begin or end like curly braces to indicate
the start and stop for the function, they have to rely on this indentation.
For example: If we write the above function without indentation, then error will occur. Following screenshot illustrates this ‒
In [2]:
def test_fun();
print("This is my first function")
Cell In[2], line 2
print("This is my
first function")
IndentationError: expected an indented block after function
definition on line 1

Python for Data Science: Chapter 2: Functions and Files : Tag: Computer Programming, Python, Data Science : - Python: Defining a Function
Python for Data Science
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation
English Essentials II
EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Tamils and Technology தமிழர்களும் தொழில்நுட்பமும்
UC25H02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
Applied Physics (CSIE) II
PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Digital Principles and Computer Organization
CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electrical and Electronics Engineering
EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Python for Data Science
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Re-Engineering for Innovation
ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Python for Data Science - Laboratory
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation