1/17
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
callable
any object that can be invoked using parentheses to perform a task
State how callables improve abstraction
They allow tasks to be initiated without focusing on their execution logic
invocation
the act of executing a callable
Explain passing
Passing is when specific date is placed within the parentheses, fitting the constraints of placeholder values known as parameters. Passing values into the parentheses creates arguments which act as their respective placeholder values in the function. Each parameter/argument is separated by a comma
delimiter
character used to separate pieces of data
function
callable objects whose sole purpose is to execute a isolated routine
isolated routine
sequenced instructions that have been packaged into a single unit
user-defined functions
those encapsulating a block of code created by a programmer
built-in functions
predefined functions created by a developer of the programming language which require no setup on behalf of the user
State the reasons why user-defined functions are beneficial (5)
They simplify tasks — breaking down components of complex tasks
Abstract operations — due to their nature as callable objects
Reusable — each time they are invoked, the same routine is called
Shareable — They can be recreated in other scripts
Increases readability — Indicating which components of a script are to be executed alongside each other
State the rules for creating user-defined functions in Python
Names cannot be keyword or contain spaces
The first character must be a letter in the English alphabet or an underscore
Following characters must be a letter in the English alphabet, an underscore or a numerical digit (0-9)
recursion
method of problem-solving in which a function calls itself to solve a smaller piece of a larger problem
State and describe the three main components of recursion
Base case — the stopping condition that ends the recursion and prevents the function from calling itself infinitely
Recursive case — the part where the function breaks the problem down into a smaller version of itself and calls the function again
Call stack - -the memory area where the computer tracks active function calls using a LIFO structure
State and describe the two main types of recursion
Head — the function makes its recursive call first. The calculations or operations for the current frame are put on hold until the recursive call returns
Tail — the recursive call is the absolute final action. No calculations are performed after the call returns
scope
the region within a program in which an object is accessible
State and describe the four types of scope
Local — objects which are defined within a function and are only accessible when that function runs.
Enclosed — objects which are in the outer function of an inner function and are also accessible within the latter
Global — objects defined at the top-level of the script which are accessible anywhere
Built-in — Objects which are pre-defined in Python and are accessible universally
State how the different scopes play a part in enhancing abstraction in Python
Local and enhanced — Aid encapsulation as it allows temporary variables to exist and be unmodifiable outside of the execution of their respective function, secluding them from the program as a whole
Global — Aid abstraction as it reduces the amount of parameters a function has to accept in the cases where the same value is used across multiple functions
Built-in — Being universally accessible inherently aids abstraction as built-in function perform predefined tasks and the alternative of defining their instructions would introduce complexities to the program
Describe lexical scoping
It refers to the accessibility of a variable in respect to its location in the code at runtime. Python uses the LEGB for variable lookup where it checks each scope one-by-one from local to enclosed to global to built-in, stopping once it finds a match