There are different types of functions in Python, depending on how they are defined and where they come from. Here are the main types:

Built-in functions

These are functions that are already defined in Python and can be used without importing any module. 

For example, print(), len(), abs(), type() etc. are built-in functions.

Functions defined in modules

These are functions that are defined in external files (called modules) that you can import and use in your code. 

For example, math.sqrt(), random.choice(), etc. are functions defined in modules. 

You need to import the module before using the function , like this: import math or from datetime import date.

User defined functions

These are functions that you create yourself using the def keyword. You can name them whatever you want and define what they do and what they return

For example, you can define a function that calculates the area of a circle like this:

def area_of_circle(radius):

    pi = 3.14 # you can also use math.pi

    area = pi * radius ** 2 # ** means power

    return area

You can then call this function with different values of radius, like this:

print(area_of_circle(5)) # prints 78.5

print(area_of_circle(10)) # prints 314.0

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.