cs1110 final

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

1/73

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 3:14 PM on 12/13/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

74 Terms

1
New cards

Abstraction

Abstraction is when one class pretends to be another through operator overloading or familiar looking methods. For example, you can use the methods len, getitem, and setitem methods to make your class act like a list. Abstraction helps a user work with a complicated concept (like image processing) by presenting it to the user in a simple-to-understand form

2
New cards

Accumulator

An accumulator is a fancy name for a variable in a for-loop that stores information computed

3
New cards

in the for-loop and which will be still available when the for-loop is complete.

4
New cards

total = 0

5
New cards

for x in range(5):

6
New cards

total = total + x

7
New cards
8
New cards

The variable total is an accumulator. It stores the sum of the values 0..4.

9
New cards

Attribute

Attributes are variables that are stored inside of an object. Instance attributes belong to an

10
New cards

object or instance. It is impossible to enforce invariants on attributes as any value can be stored in an attribute at any time.

11
New cards

Therefore, we prefer to make attributes hidden (by starting their name with an underscore), and replacing them with getters and setters.

12
New cards

Instance Attribute

Instance attributes are created by assignment statement that prefaces the object name

13
New cards

before the period. They are typically created in the class initializer

14
New cards

class attribute

Class attributes belong to the class. They are created by an assignment statement that prefaces the class name before the period. They are also created by any assignment statement in the class definition that is outside of a method definition.

15
New cards

Bottom-Up Rule

This is the rule by which Python determines which attribute or method definition to use (when the attribute is used in an expression, or the method is called). It first looks in the object folder. If it cannot find it there, it moves to the class folder for this object. It then follows the arrows from child class to parent class until it finds it. If Python reaches the folder for object (the superest class of all) and still cannot find it, it raises an error. If the attribute or method is in multiple folders, it uses the first one that it finds.

16
New cards

Class

A class is any type that is not built-in to Python (unlike int, float, bool, and str which are

17
New cards

built-in). A value of this type is called an object.

18
New cards

Class definition

This is a template or blueprint for the objects (or instances) of the class. A class defines

19
New cards

the components of each object of the class. All objects of the class have the same components, meaning they have the same attributes and methods. The only difference between objects is the values of their attributes. Using the blueprint analogy, while many houses (objects) can be built from the same blueprint, they may differ in color of rooms, wallpaper, and so on.

20
New cards
21
New cards

class():

22
New cards

specification, getters/setters, initializer, methods

23
New cards
24
New cards

usually obj is used as the super class

25
New cards

Constructor

A constructor is a function that creates a object for a class. It puts the object in heap space, and returns the name of the object (e.g. the folder name) so you can store it in a variable. A constructor has the same name as the type of the object you wish to create.

26
New cards
27
New cards

It creates an empty object folder. • It puts the folder into heap space. • It executes the initializer method init defined in the body of the class. In doing so, it - Passes the folder name to that parameter self - Passes the other arguments in order - Executes the commands in the body of init • When done with init it returns the object (folder) name as final value of expression

28
New cards
29
New cards

Example constructor call (within a statement) : color = RGB(255,0,255)

30
New cards

Default Argument

A default argument is a value that is given to a parameter if the user calling the function or method does not provide that parameter. A default argument is specified by wording the parameter as an assignment in the function header. Once you provide a default argument for a parameter, all parameters following it in the header must also have default arguments.

31
New cards
32
New cards

def foo(x,y=2,z=3):

33
New cards

In this example, the function calls foo(1), foo(1,0), foo(1,0,0), and foo(1,z=0) are all legal, while

34
New cards

foo() is not. The parameter x does not have default arguments, while y and z do.

35
New cards

Encapsulation

Encapsulation is the process of hiding parts of your data and implementation from users

36
New cards

that do not need access to that parts of your code. This includes restricting access to attributes via getters and setters, but it also includes the usage of hidden methods as well. This process makes it easier for you to make changes in your own code without breaking the code of anyone who is using your class.

37
New cards

Getter

A getter is a special method that returns the value of an instance attribute (of the same name) when called. It allows the user to access the attribute without giving the user permission to change it. It is an important part of encapsulation

38
New cards

Global Space

Global space is area of memory that stores any variable that is not defined in the body of a function. These variables include both function names and modules names, though it can include variables with more traditional values. Variables in global space remain until you explicitly erase them or until you quit Python.

39
New cards

The Heap

The heap or heap space is the area of memory that stores mutable objects (e.g. folders). It also stores function definitions, the contents of modules imported with the import command, as well as class folders. Folders in the heap remain until you explicitly erase them or until you quit Python. You cannot access the heap directly. You access them with variables in global space or in a call frame that contain the name of the object in heap space.

40
New cards

Immutable Attribute

An immutable attribute is a hidden attribute that has a getter, but no setter. This implies that a user it not allowed to alter the value of this attribute. It is an important part of encapsulation

41
New cards

Implementation

An implementation is a collection of Python code for a function, module, or class) that satisfies a specification. This code may be changed at any time as long as it continues to satisfy the specification.

42
New cards

Inheritance

Inheritance is the process by which an object can have a method or attribute even if that method or attribute was not explicitly mentioned in the class definition. If the class is a subclass, then any method or attribute is inherited from the superclass.

43
New cards

Interface

The interface is the information that another user needs to know to use a Python feature, such as a function, module, or class. The simplest definition for this is any information displayed by the help() function. For a function, the interface is typically the specification and the function header. For a class, the interface is typically the class specification as well as the list of all unhidden methods and their specifications. The interface for a module is similar to that of a class.

44
New cards

Instance

This is a synonym for an object. An object is an instance of a class.

45
New cards

Invariant

An invariant is a statement about an attribute that must always be true. It can be like a

46
New cards

precondition, in that prevents certain types of values from being assigned to the attribute. It can also be a relationship between multiple attributes, requiring that when one attribute is altered, the other attributes must be altered to match.

47
New cards

is

The is operator works like == except that it compares folder names, not contents. The meaning of the operator is can never be changed. This is different from ==, whose meaning is determined by the special operator method eq. If == is used on an object that does not have a definition for method eq, then == and is are the same.

48
New cards

isinstance.

The function call isinstance(ob,C) returns True if object ob is an instance of class C. This is different than testing the type of an object, as it will return True even if the type of ob is a subclass of C.

49
New cards

Method

Methods are functions that are stored inside of an class folder. They are defined just like a

50
New cards

function is defined, except that they are (indented) inside-of a class defintion. Methods are called by placing the object variable and a dot before the function name. The object before the dot is passed to the method definition as the argument self. Hence all method definitions must have at

51
New cards

least one parameter. If t is a time object, then we call the method defined above with the syntax t.toSeconds(). The

52
New cards

object t is passed to self

53
New cards

Mutable Attribute.

An mutable attribute is a hidden attribute that has both a getter and a setter. This implies that a user it allowed to alter the value of this attribute, provide that the invariant is not violated. It is an important part of encapsulation

54
New cards

Object

An object is a value whose type is a class. Objects typically contain attributes, which are variables inside of the object which can potentially be modified. In addition, objects often have methods, which are functions that are stored inside of the object

55
New cards

Operator Overloading

Operator overloading is the means by which Python evaluates the various operator

56
New cards

symbols, such as +, *, /, and the like. The name refers to the fact that an operator can have many different "meanings" and the correct meaning depends on the type of the objects involved. In this case, Python looks at the class or type of the object on the left. If it is a built-in type, it uses the built-in meaning for that type. Otherwise, it looks for the associated special method (beginning and ending with double underscores) in the class definition

57
New cards

Overriding a Method.

In a subclass, one can redefine a method that was defined in a superclass. This

58
New cards

is called overriding the method. In general, the overriding method is called. To call an overridden method

59
New cards

method of the superclass, use the notation

60
New cards

super().method(…)

61
New cards

If you want to access the method in a class other than the immediate parent, use

62
New cards

super(self,).method(…)

63
New cards

where is the immediate child of the class you want to access

64
New cards

Setter

A setter is a special method that can change the value of an instance attribute (of the same name)

65
New cards

when called. The purpose of the setter is to enforce any invariants. The docstring of the setter typically

66
New cards

mentions the invariants as a precondition.

67
New cards

Subclass

A subclass D is a class that extends another class C. This means that an instance of D inherits (has) all the attributes and methods that an instance of C has, in addition to the ones declared in D. In Python, every user-defined class must extend some other class. If you do not explicitly wish to extend another class, you should extend the built-in class called object (not to be confused with an object, which is an instance of a class). The built-in class object provides all of the special methods that begin and end with double underscores

68
New cards

Try-Except (Advanced)

Look at def

69
New cards

Insertion Sort

Each item is compared to next element then swapped into position (n^2)

70
New cards

Selection Sort

Find smallest unsorted element and swap with the first unsorted element (n^2)

71
New cards

quick sort

recursively partition the list → elements less than x on the left and more than x on the right (n log(n))

72
New cards

Merge Sort

73
New cards

Binary Search

list must be sorted → repeatedly divide search interval in half sorting data can speed up the process of searching data (fast, nlogn?)

74
New cards

Linear Search

looks at every element in list to check for match (slow, n)

Explore top notes

Explore top flashcards

flashcards
Fiction Review
20
Updated 1146d ago
0.0(0)
flashcards
F3 Vocabulaire Ch4.1
42
Updated 1171d ago
0.0(0)
flashcards
'24ers
25
Updated 941d ago
0.0(0)
flashcards
apush unit one terms !!!!!
42
Updated 936d ago
0.0(0)
flashcards
Preposizioni
22
Updated 797d ago
0.0(0)
flashcards
Fiction Review
20
Updated 1146d ago
0.0(0)
flashcards
F3 Vocabulaire Ch4.1
42
Updated 1171d ago
0.0(0)
flashcards
'24ers
25
Updated 941d ago
0.0(0)
flashcards
apush unit one terms !!!!!
42
Updated 936d ago
0.0(0)
flashcards
Preposizioni
22
Updated 797d ago
0.0(0)