Exam 3 Flashcards
What will the following code display?
dct = { ‘Monday’ : 1 , ‘Tuesday’ : 2, ‘Wednesday’ : 3}
print(dct[‘Tuesday’])
ANSWER would be 2 because it’s asking for the dct
What will the following code display?
dct = { ·Monday’ : 1 , ‘Tuesday’ : 2, ‘Wednesday’ : 3}
print(dct.get(‘Friday’, ‘not found’))
ANS: not found
dct = {1: [0, 1]. 2: [2, 3]. 3: [4, 51]}
print ( dct [ 3] )
ANS: [4, 51]
After the following statement executes, what elements will be stored in the myset set?
myset = set ( ‘Saturn’)
ANS: {‘S’, ‘a’, ‘t’, ‘u’, ‘r’, ‘n’}
After the following statement executes, what elements will be stored in the myset set?
myset = set( [2, 4, 4, 6, 6, 6, 6])
ANS: {2, 4, 6}
After the following statement executes, what elements will be stored in the myset set?
myset = set ( [ ‘a ‘ , ‘bb’ , ‘ccc ‘ , ‘dddd ‘ ] )
ANS: { ‘a ‘ , ‘bb’ , ‘ccc ‘ , ‘dddd ‘}
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
True
New attributes and methods may be added to a subclass
True
When a class inherits another class, it is required to use all the data attributes and methods of the superclass
False
All instances of a class share the same values of the data attributes in the class.
False
A class can be thought of as a blueprint that can be used to create an object
True
Which method is automatically executed when an instance of a class is created in memory?
ANS: __init__
Write the first line of code while creating a class named Worker?
ANS: class Worker:
What type of method provides a safe way to return a value from a class’s attribute without changing it
ANS: Accessor
In the following line of code, what is the name of the base class?
class Python(Course):
ANS: Course
Of the two classes, Cherry and Flavor, which would most likely be the subclass?
ANS: Cherry
What are the valid indexes for the string ‘New York’?
ANS: 0 through 7
What will be displayed after the following code executes?
mystr = ‘yes’
yourstr = ‘no’
mystr += yourstr * 2
print(mystr)
ANS: ‘yesnono’
What will be assigned to the variable some_nums after the following code executes?
special = ‘0123456789’, # ‘abcdfegh’
some_nums = special[0:10:2]
ANS: ‘02468’
The following expression is valid:
string[6] = ‘8’
ANS: Invalid
What is the return value of the string method lstrip()?
ANS: without leading spaces, \n, extra char,
Indexing works with both strings and lists
True
A subclass may not override any method other than the __init__ method.
false
A superclass inherits attributes and methods from its subclasses without any of them having to be rewritten.
false