Skip to content

Introduction to functions

What is a function?

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

Things to Know about functions

  1. Functions run when called
  2. A function can return a result
  3. Functions can take inputs, process them, and return an output

Advantages of using functions

  1. Helps in breaking down complex task into smaller manageable sub tasks
  2. Makes our code reusable
  3. Make our code Modular and maintainable

Types of functions

  1. Built-in functions:

    You’ve probably used some of Python built-in functions such as print(), input() Are pre-defined functions that are always made available to us needing no imports.

  2. User-defined functions:

    These functions are custom functions defined by programmers

Defining a function


Function definition is the process of specifying a step by step procedure of performing a specific task. That is reusable, and maintainable.

def sayHello():
return "Hello"