What is a method?
A method is a named, reusable block of code that performs a specific task.
Study 06 Methods and Modular Programming with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is a method?
A method is a named, reusable block of code that performs a specific task.
What does a method definition contain?
A method definition normally includes a name, parameters, and a body; it may also specify a return value.
What is a parameter?
A parameter is a named variable in a method definition, such as `name` in `def greet(name)`.
What is an argument?
An argument is the actual value supplied when a method is called, such as `"Maya"` in `greet("Maya")`.
What does a return value do?
A return value is a result sent from a method back to the code that called it.
How does returning differ from printing?
Printing displays information immediately, while returning makes the result available to the calling code for later use.
What is a local variable?
A local variable is normally accessible only within the method where it is created.
What is a method call?
A method call, or invocation, asks the program to execute a method with particular arguments.
What does `add(7, 4)` return?
`sum_value` stores `11`: `add(7, 4)` assigns the arguments to `first` and `second`, then returns their sum.
What is recursion?
Recursion occurs when a method calls itself. Every recursive method needs a base case to stop the repeated calls.
What is decomposition in programming?
Decomposition divides a complex problem into smaller subproblems, often implemented as focused methods.
Why decompose a program into methods?
Focused decomposition improves clarity, allows independent testing, supports reuse, simplifies maintenance, and helps isolate bugs.