Home » Chapter 6
Functions
Functions in programming are reusable blocks of code that preform a specific task. Functions help programmers create reusable, modular, and manageable code. In Python, there are two main categories of functions: built-in functions and programmer-defined functions. Built-in functions are those that are included in Python and are always accessible. For example, print() is a built-iun function that we have used extensively so far in this book. The other category is programmer-defined functions which are created by the programmer to perform specific tasks. Once the programmer has written a function, it can be called (executed) just like any built-in function, by invoking the name of the function and including any necessary parameters inside a following set of parentheses, like this:
my_function(10)
In this exmple, "my_function" is the name given to the function by the programmer, and the number inside the parentheses is an example of a parameter. By using functions, both built-in and programmer-defined, programmers can simplify complex problems, reduce code redundancy, and enhance the readability and maintainability of their code.