Python Programming — Data Types & Lists
Python fundamentals to advanced for interviews
9 Questions 10 Topics Take Test
Advertisement
Showing 1–9 of 9 questions in Data Types & Lists
What will this code produce?
my_list = [3, 1, 4, 1, 5]
my_list.sort()
print(my_list)
A [5, 4, 3, 1, 1]
B [1, 1, 3, 4, 5]
C [3, 1, 4, 1, 5]
D Error
Correct Answer:  B. [1, 1, 3, 4, 5]
EXPLANATION

sort() arranges list elements in ascending order by default. It modifies the list in-place.

Take Test
What will be the output?
my_list = [[1, 2], [3, 4], [5, 6]]
print(my_list[1][0])
A 2
B 3
C 4
D 5
Correct Answer:  B. 3
EXPLANATION

my_list[1] returns [3, 4], and [3, 4][0] returns 3 (first element of the nested list).

Take Test
How many times will the value 2 appear in the output?
my_list = [1, 2, 2, 3, 2, 4]
print(my_list.count(2))
A 1
B 2
C 3
D 4
Correct Answer:  C. 3
EXPLANATION

count() returns the number of occurrences of a value. The value 2 appears 3 times in the list.

Take Test
What will be the output?
my_list = [1, 2, 3]
my_list.extend([4, 5])
print(my_list)
A [1, 2, 3, [4, 5]]
B [1, 2, 3, 4, 5]
C [4, 5]
D Error
Correct Answer:  B. [1, 2, 3, 4, 5]
EXPLANATION

extend() unpacks the iterable and adds individual elements. append() would add the list as a single element.

Take Test
What is the difference between list and tuple in Python?
A Lists are mutable, tuples are immutable
B Tuples are mutable, lists are immutable
C Both are identical
D Lists use [], tuples use {} only
Correct Answer:  A. Lists are mutable, tuples are immutable
EXPLANATION

Lists (created with []) can be modified after creation, while tuples (created with ()) cannot be changed after initialization.

Take Test
Advertisement
Which of the following will return True?
my_list = [1, 2, 3]
result = 2 in my_list
A True
B False
C Error
D None
Correct Answer:  A. True
EXPLANATION

The 'in' operator checks membership. Since 2 exists in my_list, the expression evaluates to True.

Take Test
What will be printed?
my_list = [10, 20, 30]
my_list[1] = 25
print(my_list)
A [10, 20, 30]
B [10, 25, 30]
C [25, 20, 30]
D Error
Correct Answer:  B. [10, 25, 30]
EXPLANATION

Lists are mutable. Assignment my_list[1] = 25 changes the element at index 1 from 20 to 25.

Take Test
Which statement correctly creates a list of numbers from 1 to 5?
A list(range(1, 5))
B list(range(1, 6))
C [1, 2, 3, 4, 5]
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

range(1, 6) generates 1 to 5 (exclusive end), and explicit list [1,2,3,4,5] both work. Both statements are correct.

Take Test
What is the output of: len([1, [2, 3], 4, [5, [6, 7]]])?
A 7
B 4
C 5
D 6
Correct Answer:  B. 4
EXPLANATION

len() counts the number of top-level elements in the list: 1, [2,3], 4, and [5,[6,7]] = 4 elements total.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips