What is the difference between a function definition and a function call?
A function definition describes a routine; a function call executes its body with particular argument values. Defining a function normally does not run its body immediately.
Study 06. Procedures and Functions with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is the difference between a function definition and a function call?
A function definition describes a routine; a function call executes its body with particular argument values. Defining a function normally does not run its body immediately.
How do parameters differ from arguments?
A parameter is a variable in a function definition; an argument is the actual value supplied when the function is called.
What does a return statement do?
return sends a result back to the calling code and ends the current function call. Statements after an executed return are not run.
What does Python return when a function ends without a value?
If a Python function reaches its end without returning a value, it returns None.
How do positional and default arguments work?
Positional arguments normally match parameters in order. A default parameter value is used when that argument is omitted, as with exponent=2 in power(5).
What is local-variable scope?
Scope is the region where a name can be accessed. A variable created inside a function is usually local to that function call and cannot normally be accessed directly outside it.
Why should functions minimize dependence on global variables?
Passing required data as parameters and returning results explicitly makes a function’s dependencies visible. Heavy reliance on global variables makes programs harder to test and understand.
What is a side effect?
A side effect changes something outside the function, such as printing output, modifying a shared list, changing a file, or updating a user interface.
What characterizes a pure function?
A pure function depends only on its parameters and returns a result without changing outside state. The same inputs produce the same output.
What is decomposition in programming?
Decomposition divides a large problem into smaller subproblems, each handled by a function with a clear responsibility.
What does function abstraction provide?
An abstraction hides implementation details behind a simpler interface. Users need the function’s name, inputs, and result rather than every statement inside it.
What qualities make a function useful?
A useful function has a focused purpose, descriptive name, clear parameters, a predictable return value or side effect, and minimal hidden global-state dependence.