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

A

True

23
Q

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

A

false

24
Q

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

A

false

25
Q

An “is a” relashonship exists between a grasshopper and a bumblebee

A

false

26
Q

base classes are also called

A

superclass

27
Q

Each subclass has a method named __init__ that overrides the superclass’s __init__ method.

A

true

28
Q
class clock:
def \_\_init\_\_(self, shape, color, price):
self._shape = shape
self.color = color
self.price = price
A

3 mutator, 3 accessor

29
Q

In a UML diagram depicting inheritance, you only need to write the name of the subclass.

A

false

30
Q

In an inheritance relationship, what is a specialized class called?

A

a subclass

31
Q

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

class Python(Course):

A

course

32
Q

In the following line of code, what is the name of the subclass?

class Rose(Flower):

A

rose

33
Q

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

A

cherry

34
Q

One problem with using a UML diagram is that there is no way to indicate inheritance.

A

false lol the whole point of the diagram is to show inheritance

35
Q

Polymorphism works on any two class methods that have the same name.

A

true

36
Q

what does a subclass inherit from a superclass?

A

atrributes and methods

37
Q

what gives a program the ability to call the correct method depending on the type of object that is used to call it?

A

Pollymorphism

38
Q

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

A

false

39
Q

When there are several classes that have many common data attributes, it is better to write a(n) ________ to hold all the general data.

A

superclass

40
Q

Which of the following is the correct syntax for defining a class, table, which inherits from the furniture class?

A

class table(furniture):

41
Q

________ allows a new class to inherit members of the class it extends.

A

inheritance

42
Q

________ has the ability to define a method in a subclass and then define a method with the same name in a superclass.

A

polymorphism

43
Q

what does it mean to say there is an “is a” relationship between two objects?

A

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
Q

In an inheritance relationship, the _____ is the general class.

a. subclass
b. superclass
c. slave class
d. child class

A

superclass