A function is a named section of code designed to perform a particular operation. It takes input, called parameters, processes it, and returns an output. Functions help organize code into manageable sections.
In programming, functions are essential for reducing repetition and enhancing clarity. For example, a function to calculate the area of a rectangle can be reused multiple times with different inputs without rewriting the code.
Here’s a simple example in Python: 'def calculate_area(width, height): return width * height'. This function can be called with different values for width and height to get the area of various rectangles.