Final Exam 3 for PYTHON

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/124

flashcard set

Earn XP

Description and Tags

I am so done with this class bruh

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

125 Terms

1
New cards

Procedural programming:

writing programs made of functions that perform specific tasks; Procedures typically operate on data items that are separate from the procedures

2
New cards

Object-oriented programming:

focused on creating objects

3
New cards

Object

entity that contains data and procedures

4
New cards

Encapsulation

combining data and code into a single object

5
New cards

data hiding

object’s data attributes are hidden from code outside the object

6
New cards

data attributes

define the state of an object

7
New cards

public methods

allow external code to manipulate the object

8
New cards

private methods

used for object’s inner workings

9
New cards

class

code that specifies the data attributes and methods of a particular type of object

10
New cards

instance

an object created from a class

11
New cards

class definition

set of statements that define a class’s methods and data attributes

12
New cards

self parameter

required in every method in the class—references the specific object that the method is working on

13
New cards

initializer method

method automatically executed when an instance of the class is created; initialized objects data attributes and assigns self parameter to the object created

14
New cards

__

what is placed in front of the attributes name to make it private

15
New cards

object’s state

the values of the object’s attributes at a given moment

16
New cards

__str__ method

displays the object’s State; automatically called when the object is passed as an argument to the print function or passed as an argument to the str function

17
New cards

instance attribute

attributes belonging to a specific instance of a class

18
New cards

accessor methods

method that returns a value from a class’s attributes without changing it

19
New cards

mutator methods

method that stores or changes the value of a data attribute

20
New cards

Unified Modeling Language diagram

standard diagrams for graphically depicting object-oriented systems

21
New cards

top section

section of UML with name of the class

22
New cards

middle section

section of uml with the list of data attributes

23
New cards

bottom section

section of uml with the list of class methods

24
New cards

nouns

what you should look for in a description to figure out what the classes should be

25
New cards

dictionary

object that stores a collection of data

26
New cards

key

the immutable identity for the element in a dictionary

27
New cards

dictionary = {key1:value1}

format for creating a dictionary

28
New cards

false

true or false: dictionaries are sorted

29
New cards

dictionary[key]

general format for retrieving value from dictionary

30
New cards

true

true or false: a keyerror is returned if you call a dictionary with a nonexistent key

31
New cards

in

operator used to test whether a key is in a dictionary

32
New cards

true

true or false: dictionaries are mutable

33
New cards

dictionary[key]=value

format to add or change a key-pair value in a dictionary

34
New cards

del dictionary[key]

format to delete a key-value pair

35
New cards

len function

used to obtain number of elements in a dictionary

36
New cards

true

true or false: Values stored in a single dictionary can be of different types

37
New cards

dict()

built in function that creates an empty dictionary

38
New cards

clear method

deletes all the elements in a dictionary, leaving it empty

39
New cards

get method

gets a value associated with specified key from the dictionary

40
New cards

dictionary.get(key, default)

format for get method (returns default if key is not found)

41
New cards

items method

returns all the dictionaries keys and associated values; Each element in dictionary view is a tuple which contains a key and its associated value

42
New cards

keys method

returns all the dictionaries keys as a sequence

43
New cards

pop method

returns value associated with specified key and removes that key-value pair from the dictionary

44
New cards

dictionary.pop(key, default)

format for pop method; default is returned if key not found

45
New cards

popitem method

returns a randomly selected key-value pair as a tuple and removes that key-value pair from the dictionary

46
New cards

values method

returns all the dictionaries values as a sequence

47
New cards

set

object that stores a collection of data in same way as mathematical set

48
New cards

false

true or false: sets cannot have elements of different data types

49
New cards

set()

format of function used to create an empty set

50
New cards

‘a’,’b’,’c’

what a set contains if set(‘abc’) is passed

51
New cards

‘abc’

what a set contains if set([‘set’])

52
New cards

true

true or false: sets are mutable

53
New cards

add method

adds an element to a set

54
New cards

update method

adds a group of elements to a set

55
New cards

remove method

removes the specified item from the set WITH CAUSING A KEYERROR

56
New cards

discard method

removes the specified item from the set WITHOUT CAUSING A KEYERROR

57
New cards

clear method

clears all the elements of the set

58
New cards

union of two sets

a set that contains all the elements of both sets

59
New cards

set1.union(set2)

union method format

60
New cards

set1 l set2

operator for union method

61
New cards

intersection of two sets

a set that contains only the elements found in both sets

62
New cards

set1.intersection(set2)

format for intersection method

63
New cards

set1 & set2

operator for intersection method

64
New cards

difference of two sets

a set that contains the elements that appear in the first set but do not appear in the second set

65
New cards

set1.difference(set2)

difference method format

66
New cards

set1 - set2

difference method operator

67
New cards

Symmetric difference of two sets

a set that contains the elements that are not shared by the two sets

68
New cards

set1.symmetric_difference(set2)

symmetric_difference method format

69
New cards

set1 ^ set2

symmetric_difference method operator

70
New cards

subset

small set that is in a bigger set

71
New cards

superset

a large set that contains all the elements of a smaller set

72
New cards

setA.issubset(setB)

To determine whether set A is subset of set B

73
New cards

setA <= setB

To determine whether set A is subset of set B operator

74
New cards

setA.issuperset(setB)

To determine whether set A is superset of set B

75
New cards

setA >= setB

To determine whether set A is superset of set B operator

76
New cards

Serialize an object

convert the object to a stream of bytes that can easily be stored in a file (turning an object into computer words)

77
New cards

pickling

term meaning serializing an object

78
New cards

pickle

what you import to pickle and stuff

79
New cards

pickle.dump(object, file)

function to pickle objects to a file

80
New cards

unpickling

retrieving pickled object

81
New cards

pickle.load(file)

format to get pickled object from a file

82
New cards

{‘a’,’b’,’c’,’d’,’e’,’f’}

set1= {‘a’,’b’,’c’,’d’}

set2={‘c’,’d’,’e’,’f’}

set3=set1 | set2

83
New cards

{‘c’,’d’}

set1= {‘a’,’b’,’c’,’d’}

set2={‘c’,’d’,’e’,’f’}

set3=set1 & set2

84
New cards

{‘a’,’b’}

set1= {‘a’,’b’,’c’,’d’}

set2={‘c’,’d’,’e’,’f’}

set3=set1 - set2

85
New cards

{‘e’,’f’}

set1= {‘a’,’b’,’c’,’d’}

set2={‘c’,’d’,’e’,’f’}

set3= set2- set1

86
New cards

{‘a’,b’,’e’,’f’}

set1= {‘a’,’b’,’c’,’d’}

set2={‘c’,’d’,’e’,’f’}

set3=set1 ^ set2

87
New cards

sequence

an object that contains multiple items of data

88
New cards

list

an object that contains multiple data items and is mutible

89
New cards

list(object)

function converting objects to list

90
New cards

element

an item in a list

91
New cards

true

true or false lists can hold items of different types

92
New cards

list=[item1, item2, item3]

format for list assignment statement

93
New cards

repetition operator

makes multiple copies of a list and joins them together

94
New cards

index

a number specifying the position of an element in a list

95
New cards

0

index of first element in a list

96
New cards

-1

index of last element in a list

97
New cards

IndexError

raised if invalid index is used YOU CAN ONLY USE THE INDEX YOU HAVE

98
New cards

len function

returns the length of a sequence such as a list

eg: size = len(my_list)

99
New cards

mutable sequence

a sequence in which the items in the sequence can be changed

100
New cards

list[x] = new_value

format to assign a new value to a list element