61
What will be the output of the following Python code?
>>> a=[14,52,7]
>>>> b=a.copy()
>>> b is a
A)
True
B)
False
Answer & Solution
Answer: Option
B
62
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()?
A)
[3, 4, 5, 20, 5, 25, 1, 3]
B)
[1, 3, 3, 4, 5, 5, 20, 25]
C)
[25, 20, 5, 5, 4, 3, 3, 1]
D)
[3, 1, 25, 5, 20, 5, 4, 3]
Answer & Solution
Answer: Option
D
63
What will be the output of the following Python code?
names1 = ['Amir', 'Bear', 'Charlton', 'Daman']
names2 = names1
names3 = names1[:]
names2[0] = 'Alice'
names3[1] = 'Bob'
sum = 0
for ls in (names1, names2, names3):
if ls[0] == 'Alice':
sum += 1
if ls[1] == 'Bob':
sum += 10
print sum
A)
11
B)
12
C)
21
D)
22
Answer & Solution
Answer: Option
B
64
What is the list comprehension equivalent for: list(map(lambda x:x**-1, [1, 2, 3]))?
A)
[1|x for x in [1, 2, 3]]
B)
[-1**x for x in [1, 2, 3]]
C)
[x**-1 for x in [1, 2, 3]]
D)
[x^-1 for x in range(4)]
Answer & Solution
Answer: Option
C
65
What will be the output of the following Python code?
[ord(ch) for ch in 'abc']
A)
[97, 98, 99]
B)
['97', '98', '99']
C)
[65, 66, 67]
D)
Error
Answer & Solution
Answer: Option
A
66
What will be the output of the following Python code?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
B = [[3, 3, 3],
[4, 4, 4],
[5, 5, 5]]
[B[row][col]*A[row][col] for row in range(3) for col in range(3)]
A)
[3, 6, 9, 16, 20, 24, 35, 40, 45]
B)
Error
C)
[0, 30, 60, 120, 160, 200, 300, 350, 400]
D)
0
Answer & Solution
Answer: Option
A
67
Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1)?
A)
[3, 4, 5, 20, 5, 25, 1, 3]
B)
[1, 3, 3, 4, 5, 5, 20, 25]
C)
[3, 5, 20, 5, 25, 1, 3]
D)
[1, 3, 4, 5, 20, 5, 25]
Answer & Solution
Answer: Option
C
68
What is the output when we execute list("hello")?
A)
['h', 'e', 'l', 'l', 'o']
B)
['hello']
C)
['llo']
D)
['olleh']
Answer & Solution
Answer: Option
A
69
What is the output of print(k) in the following Python code snippet?
k = [print(i) for i in my_string if i not in "aeiou"]
print(k)
A)
all characters of my_string that aren't vowels
B)
a list of Nones
C)
list of Trues
D)
list of Falses
Answer & Solution
Answer: Option
B
70
Write a list comprehension equivalent for the Python code shown below.
for i in range(1, 101):
if int(i*0.5)==i*0.5:
print(i)
A)
[i for i in range(1, 100) if int(i*0.5)==(i*0.5)]
B)
[i for i in range(1, 101) if int(i*0.5)==(i*0.5)]
C)
[i for i in range(1, 101) if int(i*0.5)=(i*0.5)]
D)
[i for i in range(1, 100) if int(i*0.5)=(i*0.5)]
Answer & Solution
Answer: Option
B