Code reuse means incorporating existing code into a new program instead of writing the same functionality again. Reusable code can be treated as a black box: provide inputs, let it perform its behavior, and use its output. section 20.2
Replacing copy-and-paste code
Instead of repeating four operations for every pair of numbers, wrap the operations and reuse the wrapper: a = 1 b = 2 < wrapper for operations_with_a_and_b > a = 3 b = 4 < wrapper for operations_with_a_and_b > The values change, but the operation code stays in one reusable place. In Python, these wrappers are functions. section 20.2
Reuse helps programs by allowing you to:
- Avoid copying and pasting the same operations for different inputs. section 20.2
- Call one function with different kinds of suitable data, such as temperatures, ages, or weights. section 23.4
- Reuse a function that reads one data format for another file organized in the same format. section 23.4
- Build more complex programs from existing functions, objects, and libraries rather than creating everything from scratch. section 35.0
A black-box diagram shows the shared operation bundle receiving two numbers and producing the results of addition, subtraction, multiplication, and division. section 20.2





