What is the output of the following code?
a_list = ['a', 10, 1.23, 'Tom']
b_tuple = (1, 2, 3, 4, 5, 6)
print(a_list.index('Tom') + b_tuple.index(5)) correct answers 7
When you try to open a file with the mode 'w' and if the file does not exist, what happens?
correct answers File is created
The name used to refer to the current instance of a class within the class definition is correct
answers self
In Python, whatever you enter as input, the input() function converts it into correct answers
string
What is the output of the following program?
class Student:
def __init__(self, name, id):
self.name = name
self.id = id
def print_info(self, address):
self.address = address
print(self.name)
print(self.id)
print(self.address)
class GradStudent(Student):
s1 = GradStudent('Tom Smith', 'G001')
, s1.print_info('123 Main St') correct answers Tom Smith
G0001
123 Main St
What is the output of the following program?
a_list = [-10, 10, -20, 20, -30, 30]
b_list = [i*10 if i > 0 else i + 10 for i in a_list]
print(b_list) correct answers [0, 100, -10, 200, -20, 300]
The syntax for invoking a class method is the same as the syntax for calling a function. correct
answers False
dict1 = {'a': 10, 'b': 20, 'c': 30}
dict2 = {'c': 30, 'a': 10, 'b': 20}
print(dict1 != dict2 correct answers False (location for dictionaries don't matter)
Class methods are defined within a class and perform some action helpful to that specific type of
object. correct answers True
What is the output of the following code?
a = 'Hello, World'
print(a[-2:]) correct answers ld
What is the code to loop over the keys of the following dictionary?
Ad = {'a': 10, 'b': 20, 'c': 30, 'd': 40} correct answers for i in Ad:
print(i)
what is the output of the following code: