Computer Science · Ch 7 — Functions
User Defined Functions
User Defined Functions
Because functions are reusable, Python ships with a very large number of them ready-made: the standard library (explored in Section 7.5) contains functions we can call in our programs without ever defining them ourselves — input(), print() and int() are everyday examples.
But the standard library cannot anticipate every task. In addition to the library's functions, a programmer can define new functions while writing a program. Such functions are called user defined functions.
Definition: a function written by the programmer to achieve some task as per his or her own requirement is a user defined function. The functions cyl(), con() and post_tax_price() written for the tent program in Section 7.2 are all user defined functions.
The sub-sections that follow cover the full mechanics of user defined functions:
- 7.3.1 — Creating a user defined function: the
defstatement and the rules of a function definition. …