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