Question
1. What will be the output of the following Python code? l1=[1, 2, 3, [4]] l2=list(l1) id(l1)==id(l2) a) True b) False c) Error d) Address
1. What will be the output of the following Python code?
l1=[1, 2, 3, [4]]
l2=list(l1)
id(l1)==id(l2)
a) True
b) False
c) Error
d) Address of l1
2. Choose the function whose output can be: <_sre.SRE_Match object; span=(4, 8), match='aaaa'>.
a) >>> re.search('aaaa', "alohaaaa", 0)
b) >>> re.match('aaaa', "alohaaaa", 0)
c) >>> re.match('aaa', "alohaaa", 0)
d) >>> re.search('aaa', "alohaaa", 0)
3. What will be the output of the following Python code?
x = ['ab', 'cd']
print(len(map(list, x)))
a) [2, 2]
b) 2
c) 4
d) none of the mentioned
4. What will be the output of the following Python code?
random.randrange(1,100,10)
a) 32
b) 67
c) 91
d) 80
5. When will the else part of try-except-else be executed?
a) always
b) when an exception occurs
c) when no exception occurs
d) when an exception occurs in to except block
6. What will be the output of the following Python code?
pickle.HIGHEST_PROTOCOL
a) 4
b) 5
c) 3
d) 6
7. Which of the following is false about "import modulename" form of import?
a) The namespace of imported module becomes part of importing module
b) This form of import prevents name clash
c) The namespace of imported module becomes available to importing module
d) The identifiers in module are accessed as: modulename.identifier
8. How do you get the name of a file from a file object (fp)?
a) fp.name
b) fp.file(name)
c) self.__name__(fp)
d) fp.__name__()
9. What will be the output of the following Python function?
sum(2,4,6)
sum([1,2,3])
a) Error, 6
b) 12, Error
c) 12, 6
d) Error, Error
10. What will be the output of the following Python code?
list(map((lambda x:x**2), filter((lambda x:x%2==0), range(10))))
a) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
b) [0, 4, 16, 36, 64]
c) Error
d) No output
11. What will be the output of the following Python code if the input entered is 6?
valid = False
while not valid:
try:
n=int(input("Enter a number"))
while n%2==0:
print("Bye")
valid = True
except ValueError:
print("Invalid")
a) Bye (printed once)
b) No output
c) Invalid (printed once)
d) Bye (printed infinite number of times)
12. What will be the output of the following Python code, if the time module has already been imported?
def num(m):
t1 = time.time()
for i in range(0,m):
print(i)
t2 = time.time()
print(str(t2-t1))
num(3)
a)
1
2
3
The time taken for the execution of the code
b)
3
The time taken for the execution of the code
c)
1
2
3
UTC time
d)
3
UTC time
13. The single line equivalent of the following Python code?
l=[1, 2, 3, 4, 5]
def f1(x):
return x<0
m1=filter(f1, l)
print(list(m1))
a) filter(lambda x:x<0, l)
b) filter(lambda x, y: x<0, l)
c) filter(reduce x<0, l)
d) reduce(x: x<0, l)
14. What will be the output of the following Python code?
x = ['ab', 'cd']
print(len(list(map(list, x))))))
a) 2
b) 4
c) error
d) none of the mentioned
15. What will be the output of the following Python code?
class A:
def test1(self):
print(" test of A called ")
class B(A):
def test(self):
print(" test of B called ")
class C(A):
def test(self):
print(" test of C called ")
class D(B,C):
def test2(self):
print(" test of D called ")
obj=D()
obj.test()
a)
test of B called
test of C called
b)
test of C called
test of B called
c) test of B called
d) Error, both the classes from which D derives has same method test()
16. Read the following Python code carefully and point out the global variables?
y, z = 1, 2
def f():
global x
x = y+z
a) x
b) y and z
c) x, y and z
d) Neither x, nor y, nor z
17. To open a file c:\scores.txt for reading, we use _________
a) infile = open("c:\scores.txt", "r")
b) infile = open("c:\\scores.txt", "r")
c) infile = open(file = "c:\scores.txt", "r")
d) infile = open(file = "c:\\scores.txt", "r")
18. What will be the output of the following Python function?
len(["hello",2, 4, 6])
a) 4
b) 3
c) Error
d) 6
19. What will be the output of the following Python code?
class A:
def __init__(self):
self._x = 5
class B(A):
def y(self):
print(self._x)
def main():
obj = B()
obj.display()
main()
a) Error, invalid syntax for object declaration
b) Nothing is printed
c) 5
d) Error, private class member can't be accessed in a subclass
20. What will be the output of the following Python code?
class A:
def test(self):
print("test of A called")
class B(A):
def test(self):
print("test of B called")
super().test()
class C(A):
def test(self):
print("test of C called")
super().test()
class D(B,C):
def test2(self):
print("test of D called")
obj=D()
obj.test()
a)
test of B called
test of C called
test of A called
b)
test of C called
test of B called
c)
test of B called
test of C called
d) Error, all the three classes from which D derives has same method test()
21. What will be the output of the following Python function?
oct(7)
oct('7')
a)
Error
07
b)
0o7
Error
c)
0o7
Error
d)
07
0o7
22. Suppose B is a subclass of A, to invoke the init method in A from B, what is the line of code you should write?
a) A.__init__(self)
b) B.__init__(self)
c) A.__init__(B)
d) B.__init__(A)
23. Which of these about a dictionary is false?
a) The values of a dictionary can be accessed using keys
b) The keys of a dictionary can be accessed using values
c) Dictionaries aren't ordered
d) Dictionaries are mutable
24. What does single-level inheritance mean?
a) A subclass derives from a class which in turn derives from another class
b) A single superclass inherits from multiple subclasses
c) A single subclass derives from a single superclass
d) Multiple base classes inherit a single derived class
25. The function divmod(a,b), where both 'a' and 'b' are integers is evaluated as:
a) (a%b, a//b)
b) (a//b, a%b)
c) (a//b, a*b)
d) (a/b, a%b)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started