1/124
I am so done with this class bruh
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Procedural programming:
writing programs made of functions that perform specific tasks; Procedures typically operate on data items that are separate from the procedures
Object-oriented programming:
focused on creating objects
Object
entity that contains data and procedures
Encapsulation
combining data and code into a single object
data hiding
object’s data attributes are hidden from code outside the object
data attributes
define the state of an object
public methods
allow external code to manipulate the object
private methods
used for object’s inner workings
class
code that specifies the data attributes and methods of a particular type of object
instance
an object created from a class
class definition
set of statements that define a class’s methods and data attributes
self parameter
required in every method in the class—references the specific object that the method is working on
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
__
what is placed in front of the attributes name to make it private
object’s state
the values of the object’s attributes at a given moment
__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
instance attribute
attributes belonging to a specific instance of a class
accessor methods
method that returns a value from a class’s attributes without changing it
mutator methods
method that stores or changes the value of a data attribute
Unified Modeling Language diagram
standard diagrams for graphically depicting object-oriented systems
top section
section of UML with name of the class
middle section
section of uml with the list of data attributes
bottom section
section of uml with the list of class methods
nouns
what you should look for in a description to figure out what the classes should be
dictionary
object that stores a collection of data
key
the immutable identity for the element in a dictionary
dictionary = {key1:value1}
format for creating a dictionary
false
true or false: dictionaries are sorted
dictionary[key]
general format for retrieving value from dictionary
true
true or false: a keyerror is returned if you call a dictionary with a nonexistent key
in
operator used to test whether a key is in a dictionary
true
true or false: dictionaries are mutable
dictionary[key]=value
format to add or change a key-pair value in a dictionary
del dictionary[key]
format to delete a key-value pair
len function
used to obtain number of elements in a dictionary
true
true or false: Values stored in a single dictionary can be of different types
dict()
built in function that creates an empty dictionary
clear method
deletes all the elements in a dictionary, leaving it empty
get method
gets a value associated with specified key from the dictionary
dictionary.get(key, default)
format for get method (returns default if key is not found)
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
keys method
returns all the dictionaries keys as a sequence
pop method
returns value associated with specified key and removes that key-value pair from the dictionary
dictionary.pop(key, default)
format for pop method; default is returned if key not found
popitem method
returns a randomly selected key-value pair as a tuple and removes that key-value pair from the dictionary
values method
returns all the dictionaries values as a sequence
set
object that stores a collection of data in same way as mathematical set
false
true or false: sets cannot have elements of different data types
set()
format of function used to create an empty set
‘a’,’b’,’c’
what a set contains if set(‘abc’) is passed
‘abc’
what a set contains if set([‘set’])
true
true or false: sets are mutable
add method
adds an element to a set
update method
adds a group of elements to a set
remove method
removes the specified item from the set WITH CAUSING A KEYERROR
discard method
removes the specified item from the set WITHOUT CAUSING A KEYERROR
clear method
clears all the elements of the set
union of two sets
a set that contains all the elements of both sets
set1.union(set2)
union method format
set1 l set2
operator for union method
intersection of two sets
a set that contains only the elements found in both sets
set1.intersection(set2)
format for intersection method
set1 & set2
operator for intersection method
difference of two sets
a set that contains the elements that appear in the first set but do not appear in the second set
set1.difference(set2)
difference method format
set1 - set2
difference method operator
Symmetric difference of two sets
a set that contains the elements that are not shared by the two sets
set1.symmetric_difference(set2)
symmetric_difference method format
set1 ^ set2
symmetric_difference method operator
subset
small set that is in a bigger set
superset
a large set that contains all the elements of a smaller set
setA.issubset(setB)
To determine whether set A is subset of set B
setA <= setB
To determine whether set A is subset of set B operator
setA.issuperset(setB)
To determine whether set A is superset of set B
setA >= setB
To determine whether set A is superset of set B operator
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)
pickling
term meaning serializing an object
pickle
what you import to pickle and stuff
pickle.dump(object, file)
function to pickle objects to a file
unpickling
retrieving pickled object
pickle.load(file)
format to get pickled object from a file
{‘a’,’b’,’c’,’d’,’e’,’f’}
set1= {‘a’,’b’,’c’,’d’}
set2={‘c’,’d’,’e’,’f’}
set3=set1 | set2
{‘c’,’d’}
set1= {‘a’,’b’,’c’,’d’}
set2={‘c’,’d’,’e’,’f’}
set3=set1 & set2
{‘a’,’b’}
set1= {‘a’,’b’,’c’,’d’}
set2={‘c’,’d’,’e’,’f’}
set3=set1 - set2
{‘e’,’f’}
set1= {‘a’,’b’,’c’,’d’}
set2={‘c’,’d’,’e’,’f’}
set3= set2- set1
{‘a’,b’,’e’,’f’}
set1= {‘a’,’b’,’c’,’d’}
set2={‘c’,’d’,’e’,’f’}
set3=set1 ^ set2
sequence
an object that contains multiple items of data
list
an object that contains multiple data items and is mutible
list(object)
function converting objects to list
element
an item in a list
true
true or false lists can hold items of different types
list=[item1, item2, item3]
format for list assignment statement
repetition operator
makes multiple copies of a list and joins them together
index
a number specifying the position of an element in a list
0
index of first element in a list
-1
index of last element in a list
IndexError
raised if invalid index is used YOU CAN ONLY USE THE INDEX YOU HAVE
len function
returns the length of a sequence such as a list
eg: size = len(my_list)
mutable sequence
a sequence in which the items in the sequence can be changed
list[x] = new_value
format to assign a new value to a list element