What is Function? Definition, Meaning & Example
A reusable block of code that performs a specific task and can be called multiple times.
TL;DR: A reusable block of code that performs a specific task and can be called multiple times.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Function: A reusable block of code that performs a specific task and can be called multiple times.
Explanation
Functions promote code reuse and organization. Functions take parameters and return values. Local variables in functions are only accessible within the function. Recursive functions call themselves. Functions can be nested inside other functions. Well-designed functions are single-purpose and easy to test.
Example
A function that adds two numbers: def add(a, b): return a + b can be called multiple times.
Frequently Asked Questions
Why use functions?
Functions promote code reuse, improve organization, make code easier to test, and reduce errors.
What is a recursive function?
A recursive function is one that calls itself to solve a problem by breaking it into smaller subproblems.
More Computer Terms
🤖 Stuck on any of these? Ask Syllab's free AI Tutor to explain step by step →