Functions in Python
In Python a function is some reusable code that takes arguments(s) as input does some computation and then returns a result. We have already seen functions in previous lessons. For example, the print() command that we used is actually a function that allows us to print something.
In Python, there are two kinds of functions:
- Built-in functions that are provided as part of Python -
print(), type(), float(), int() ... - Functions that we define ourselves and then use
The built-in function names are treated as "new" reserved words, and should not be used as variable names. We can define a new function using the def reserved word (We will see this soon).
We call/invoke the function by using the function name, parenthesis and arguments in an expression.
Example 1 - Max()
The following is an example of the in-built max() function in Python. The max() returns the largest of its arguments.
1>>> max