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

Slice [::-1] reverses the list by using step -1 (backwards through entire list). It returns a reversed copy.

Take Test
What will be the result of executing this code?
my_list = [1, 2, 3]
my_list.insert(1, 99)
print(my_list)
A [1, 99, 2, 3]
B [99, 1, 2, 3]
C [1, 2, 99, 3]
D [1, 2, 3, 99]
Correct Answer:  A. [1, 99, 2, 3]
EXPLANATION

insert(1, 99) inserts 99 at index 1, shifting existing elements right. Result is [1, 99, 2, 3].

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

Negative indexing starts from the end: -1 is 5, -2 is 4, -3 is 3, etc. So -2 returns 4.

Take Test
What is the correct way to create a true copy of a list?
A my_copy = my_list
B my_copy = my_list.copy()
C my_copy = list(my_list)
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

Both .copy() method and list() constructor create shallow copies. Simple assignment creates only a reference.

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

Assignment creates a reference, not a copy. Both variables point to the same list object, so changes are reflected in both.

Take Test
Advertisement
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
Q.10 Medium Data Types & Lists
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
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