1/10
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What does the __repr__() function do?
define what the object looks like with a string representation, especially helpful for measurements and such
What other functions does the __repr__() work well with?
print() and str()
The __repr__()function should return….
a string representation of the object NOT print it
How to make an error happen for things that don’t belong? (playing card class)
def __init__(self,v,s):
if type(v) != type(1) or v > 14 or v < 2:
raise Exception("A PlayingCard's value must be an integer in the range 2-14.")
self.value = v
self.suit = ssame init function, just with the exception, gives python a specific error message
An attribute or method whose name starts with an underscore should be treated as…
private (shouldn’t change) ex. self._value
If you start it with two underscores, then Python performs…
name mangling, which doese’t let you change the name outside the class (can’t change) self.__value
What is a container types?
meant to hold collections of other data, like lists, dictionaries, sets and tuples
What does Queue()do?
creates a new queue that is empty. It needs no parameters and returns an empty queue.
What does enqueue(item) do?
adds a new item to the back of the queue. It needs the item and returns nothing.
What does dequeue() do?
removes the item at the front of the queue. It needs no parameters and returns the item. The queue is modified
What is an abstract data type?
is a logical description of how we view the data and the operations that are allowed without regard to how they will be implemented