Python Programming
Python fundamentals to advanced for interviews
119 Questions 10 Topics Take Test
Advertisement
Showing 11–20 of 119 questions
Q.11 Medium Data Types & Lists
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
Q.12 Medium Data Types & Lists
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
Q.13 Medium Data Types & Lists
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
Q.14 Medium Data Types & Lists
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
What will be the output?
my_list = [1, 2, 3, 4, 5]
print(my_list[1:3])
A [1, 2]
B [2, 3]
C [2, 3, 4]
D [3, 4]
Correct Answer:  B. [2, 3]
EXPLANATION

List slicing [1:3] returns elements from index 1 (inclusive) to index 3 (exclusive), which are elements at positions 1 and 2.

Take Test
Advertisement
Which method removes and returns the last element from a list?
A remove()
B pop()
C delete()
D discard()
Correct Answer:  B. pop()
EXPLANATION

pop() removes and returns the last element (or element at specified index). remove() only removes value, doesn't return it.

Take Test
What will be the type of x after executing: x = [1, 2.5, 'hello']?
A list
B mixed
C tuple
D dict
Correct Answer:  A. list
EXPLANATION

Square brackets [] create a list object. Lists in Python can contain elements of different data types (heterogeneous).

Take Test
Which of the following is NOT a valid Python data type?
A int
B string
C list
D tuple
Correct Answer:  B. string
EXPLANATION

In Python, the string data type is represented as 'str', not 'string'. 'string' is not a built-in data type.

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

append() adds one element to the list. Initial length is 3, after append(4) it becomes 4.

Take Test
Q.20 Medium Basics & Syntax
Consider the following code snippet:

python
x = [1, 2, 3]
y = x
y.append(4)
print(x)


What will be the output?
A [1, 2, 3, 4]
B [1, 2, 3]
C Error: list object does not support append
D [4]
Correct Answer:  A. [1, 2, 3, 4]
EXPLANATION

In Python, when you assign y = x, both variables reference the same list object in memory. When you modify the list using y.append(4), the original list x is also modified because they point to the same object. Therefore, print(x) outputs [1, 2, 3, 4].

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