(P1/2) COMP 1126 - Functions and Scope

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:40 AM on 10/11/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

18 Terms

1
New cards

callable

any object that can be invoked using parentheses to perform a task

2
New cards

State how callables improve abstraction

They allow tasks to be initiated without focusing on their execution logic

3
New cards

invocation

the act of executing a callable

4
New cards

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

5
New cards

delimiter

character used to separate pieces of data

6
New cards

function

callable objects whose sole purpose is to execute a isolated routine

7
New cards

isolated routine

sequenced instructions that have been packaged into a single unit

8
New cards

user-defined functions

those encapsulating a block of code created by a programmer

9
New cards

built-in functions

predefined functions created by a developer of the programming language which require no setup on behalf of the user

10
New cards

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

11
New cards

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)

12
New cards

recursion

method of problem-solving in which a function calls itself to solve a smaller piece of a larger problem

13
New cards

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

14
New cards

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

15
New cards

scope

the region within a program in which an object is accessible

16
New cards

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

17
New cards

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

18
New cards

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