In this tutorial, we would learn about Functions in Python. A function is a block of code which allow us to reuse code. Python provides us rich collection of in-built functions like print(), mkdir(), rmdir() etc. which we can use by just calling them. In Python, we can create our own functions. This kind of functions known as user-defined functions. Here we will learn How to create a function, how to call it. return statement etc.
Page Contents
Defining a function in Python
Defining a function in Python is so easy. we use def keyword in Python to define a function. Check this example to understand it.
def my_function():
print ("Hello This is my_function")
return
Here you can see we used def keyword to define a function then we wrote function name followed by (). After we wrote: symbol to state body of the function. At the end we wrote a return statement which is optional we will write a return statement without parameter this is equal to return none.
Calling a function in Python
After defining a function we can call our function any number of time in our code. Check this example.
def my_function():
print ("Hello This is my_function")
return
#calling our function Here
my_function()
Parvesh Sandila is a results-driven tech professional with 8+ years of experience in web and mobile development, leadership, and emerging technologies.
After completing his Master’s in Computer Applications (MCA), he began his journey as a programming mentor, guiding 100+ students and helping them build strong foundations in coding. In 2019, he founded Owlbuddy.com, a platform dedicated to providing free, high-quality programming tutorials for aspiring developers.
He then transitioned into a full-time programmer, where his hands-on expertise and problem-solving skills led him to grow into a Team Lead and Technical Project Manager, successfully delivering scalable web and mobile solutions. Today, he works with advanced technologies such as AI systems, RAG architectures, and modern digital solutions, while also collaborating through a strategic partnership with Technobae (UK) to build next-generation products.
