Question 1
Find the output of the following program:
d = {"geek":10, "for":45, "geeks": 90}
print("geek" in d)
10
False
True
Error
Question 2
What is the output of the following program?
li = [2e-04, 'a', False, 87]
tup = (6.22, 'boy', True, 554)
for i in range(len(li)):
if li[i]:
li[i] = li[i] + tup[i]
else:
tup[i] = li[i] + li[i]
break
[6.222e-04, ‘aboy’, True, 641]
[6.2202, ‘aboy’, 1, 641]
TypeError
[6.2202, ‘aboy’, False, 87]
Question 3
What is the output of the following program?
import sys
tup = tuple()
print(sys.getsizeof(tup), end = " ")
tup = (1, 2)
print(sys.getsizeof(tup), end = " ")
tup = (1, 3, (4, 5))
print(sys.getsizeof(tup), end = " ")
tup = (1, 2, 3, 4, 5, [3, 4], 'p', '8', 9.777, (1, 3))
print(sys.getsizeof(tup))
0 2 3 10
32 34 35 42
48 64 72 128
48 144 192 480
Question 4
What is the output of (1, 2, 3) + (4, 5, 6)?
(1, 2, 3, 4, 5, 6)
(5, 7, 9)
TypeError
(1, 2, 3, (4, 5, 6))
Question 5
What happens if we try to assign a value to an element in a tuple?
The tuple is updated.
Nothing happens.
An error is raised.
The tuple is converted to a list.
Question 6
Which of the following is a correct statement about tuple unpacking?
x, y, z = (1, 2, 3) is an invalid statement.
Tuple unpacking requires more variables than the elements in the tuple.
Tuple unpacking can be done without matching the exact number of elements
x, y, z = (1, 2, 3) unpacks the values into x, y, and z
Question 7
What is the output of tuple(map(lambda x: x*x, [1, 2, 3]))?
[1, 4, 9]
(1, 4, 9)
{1, 4, 9}
None
Question 8
What does the following tuple comprehension do? tuple(x for x in range(5))
Creates a tuple with elements 0 to 4.
Generates an error.
Creates a list instead of a tuple.
None of the above.
Question 9
Which of the following is the correct way to create a set in Python?
s = {1, 2, 3}
s = [1, 2, 3]
s = (1, 2, 3)
s = {1: "one", 2: "two", 3: "three"}
Question 10
What is the output of the following code?
s = {1, 2, 3}
s.add(4)
print(s)
{1, 2, 3}
{1, 2, 3, 4}
{1, 4}
Error
There are 18 questions to complete.