Exam 3 Flashcards

1
Q

What will the following code display?
dct = { ‘Monday’ : 1 , ‘Tuesday’ : 2, ‘Wednesday’ : 3}

print(dct[‘Tuesday’])

A

ANSWER would be 2 because it’s asking for the dct

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What will the following code display?

dct = { ·Monday’ : 1 , ‘Tuesday’ : 2, ‘Wednesday’ : 3}

print(dct.get(‘Friday’, ‘not found’))

A

ANS: not found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

dct = {1: [0, 1]. 2: [2, 3]. 3: [4, 51]}

print ( dct [ 3] )

A

ANS: [4, 51]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

After the following statement executes, what elements will be stored in the myset set?

myset = set ( ‘Saturn’)

A

ANS: {‘S’, ‘a’, ‘t’, ‘u’, ‘r’, ‘n’}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

After the following statement executes, what elements will be stored in the myset set?

myset = set( [2, 4, 4, 6, 6, 6, 6])

A

ANS: {2, 4, 6}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

After the following statement executes, what elements will be stored in the myset set?

myset = set ( [ ‘a ‘ , ‘bb’ , ‘ccc ‘ , ‘dddd ‘ ] )

A

ANS: { ‘a ‘ , ‘bb’ , ‘ccc ‘ , ‘dddd ‘}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The difference of set1 and aet2 is a set that contains only the elements that appear in set1 but do not appear in set2. T/F

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

New attributes and methods may be added to a subclass

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When a class inherits another class, it is required to use all the data attributes and methods of the superclass

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

All instances of a class share the same values of the data attributes in the class.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

A class can be thought of as a blueprint that can be used to create an object

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which method is automatically executed when an instance of a class is created in memory?

A

ANS: __init__

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Write the first line of code while creating a class named Worker?

A

ANS: class Worker:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What type of method provides a safe way to return a value from a class’s attribute without changing it

A

ANS: Accessor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In the following line of code, what is the name of the base class?

class Python(Course):
A

ANS: Course

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Of the two classes, Cherry and Flavor, which would most likely be the subclass?

A

ANS: Cherry

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the valid indexes for the string ‘New York’?

A

ANS: 0 through 7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What will be displayed after the following code executes?

mystr = ‘yes’

yourstr = ‘no’

mystr += yourstr * 2

print(mystr)

A

ANS: ‘yesnono’

19
Q

What will be assigned to the variable some_nums after the following code executes?

special = ‘0123456789’, # ‘abcdfegh’

some_nums = special[0:10:2]

A

ANS: ‘02468’

20
Q

The following expression is valid:

string[6] = ‘8’

A

ANS: Invalid

21
Q

What is the return value of the string method lstrip()?

A

ANS: without leading spaces, \n, extra char,

22
Q

Indexing works with both strings and lists

23
Q

A subclass may not override any method other than the __init__ method.

24
Q

A superclass inherits attributes and methods from its subclasses without any of them having to be rewritten.

25
An "is a" relashonship exists between a grasshopper and a bumblebee
false
26
base classes are also called
superclass
27
Each subclass has a method named __init__ that overrides the superclass's __init__ method.
true
28
``` class clock: def __init__(self, shape, color, price): self._shape = shape self.color = color self.price = price ```
3 mutator, 3 accessor
29
In a UML diagram depicting inheritance, you only need to write the name of the subclass.
false
30
In an inheritance relationship, what is a specialized class called?
a subclass
31
in the following line of code, what is the name of the base class? class Python(Course):
course
32
In the following line of code, what is the name of the subclass? class Rose(Flower):
rose
33
Of the two classes, Cherry and Flavor, which would most likely be the subclass?
cherry
34
One problem with using a UML diagram is that there is no way to indicate inheritance.
false lol the whole point of the diagram is to show inheritance
35
Polymorphism works on any two class methods that have the same name.
true
36
what does a subclass inherit from a superclass?
atrributes and methods
37
what gives a program the ability to call the correct method depending on the type of object that is used to call it?
Pollymorphism
38
When a class inherits another class, it is required to use all the data attributes and methods of the superclass.
false
39
When there are several classes that have many common data attributes, it is better to write a(n) ________ to hold all the general data.
superclass
40
Which of the following is the correct syntax for defining a class, table, which inherits from the furniture class?
class table(furniture):
41
________ allows a new class to inherit members of the class it extends.
inheritance
42
________ has the ability to define a method in a subclass and then define a method with the same name in a superclass.
polymorphism
43
what does it mean to say there is an "is a" relationship between two objects?
When one object is a specialized version of another object, there is an "is a" relationship between them. The specialized object " is a" version of the general object.
44
In an inheritance relationship, the _____ is the general class. a. subclass b. superclass c. slave class d. child class
superclass