Introduction to functions
What is a function?
A function is a block of code that performs a specific task.
Things to Know about functions
- Functions run when called
- A function can return a result
- Functions can take inputs, process them, and return an output
Advantages of using functions
- Helps in breaking down complex task into smaller manageable sub tasks
- Makes our code reusable
- Make our code Modular and maintainable
Types of functions
-
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. -
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.