Computer Science Final

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/10

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

11 Terms

1
New cards

What does the __repr__() function do?

define what the object looks like with a string representation, especially helpful for measurements and such

2
New cards

What other functions does the __repr__() work well with?

print() and str()

3
New cards

The __repr__()function should return….

a string representation of the object NOT print it

4
New cards

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 = s

same init function, just with the exception, gives python a specific error message

5
New cards

An attribute or method whose name starts with an underscore should be treated as…

private (shouldn’t change) ex. self._value

6
New cards

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

7
New cards

What is a container types?

meant to hold collections of other data, like lists, dictionaries, sets and tuples

8
New cards

What does Queue()do?

creates a new queue that is empty. It needs no parameters and returns an empty queue.

9
New cards

What does enqueue(item) do?

adds a new item to the back of the queue. It needs the item and returns nothing.

10
New cards

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

11
New cards

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