ExamVeda
Login
Home
21
What will be the output of the following code:
my_tuple = (1, 2, 3)
my_tuple[1] = 4
print(my_tuple)
Discuss
Answer & Solution
Answer: Option D
Solution:
Tuples in Python are immutable, meaning their elements cannot be changed after creation.

In the given code, my_tuple = (1, 2, 3) initializes a tuple with three elements.

The line my_tuple[1] = 4 attempts to modify the second element of the tuple, which is not allowed.

As a result, Python raises a TypeError stating that 'tuple' object does not support item assignment.

Since the code causes an error and does not produce any valid tuple as output, the correct answer is "None of these."
22
What is the output of the following code:
my_list = [1, 2, 3]
del my_list[1]
print(my_list)
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
23
What will be the output of the following code:
my_list = [3, 1, 2]
my_list.sort()
print(my_list)
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
24
What is the output of the following code:
my_list = [1, 2, 3]
my_list.insert(1, 4)
print(my_list)
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
25
What is the purpose of the count() method for lists and tuples?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
26
What will be the output of the following code:
my_list = [1, 2, 3]
my_list.reverse()
print(my_list)
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
27
What is the output of the following code:
my_list = [1, 2, 3, 4]
my_list.pop()
print(my_list)
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
28
What is the output of the following code:
my_tuple = (1, 2, 3)
print(my_tuple[1])
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
29
What is the output of the following code:
my_list = [1, 2, 3, 4]
my_list.remove(2)
print(my_list)
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
30
What will the following code output:
my_tuple = (1, 2, 3)
new_tuple = my_tuple.copy()
print(new_tuple)
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board