A function is a piece of code that is only written once and can be executed whenever the program calls for it. A function is a self-contained block of statements with a valid name, list of parameters, and body. Capabilities make programming more practical and particular to perform measured assignments. There are a number of built-in functions for completing tasks in Python, and the user can also create new functions.
Functions fall into three categories:
Built-In Functions: duplicate(), len(), count() are the a few implicit capabilities.
User-defined Functions: User-defined functions are functions that are defined by a user.
Anonymous functions: Because they are not declared using the standard def keyword, these functions are also referred to as lambda functions.
Example: A general syntax of user defined function is given below.
- def function_name(parameters list):
- #— statements—
- return a_value