Which of the following is NOT a valid Python data type?
Answer: B
In Python, the string data type is represented as 'str', not 'string'. 'string' is not a built-in data type.
Q.102Easy
What will be the type of x after executing: x = [1, 2.5, 'hello']?
Answer: A
Square brackets [] create a list object. Lists in Python can contain elements of different data types (heterogeneous).
Q.103Easy
Which method removes and returns the last element from a list?
Answer: B
pop() removes and returns the last element (or element at specified index). remove() only removes value, doesn't return it.
Q.104Easy
What will be the output?
my_list = [1, 2, 3, 4, 5]
print(my_list[1:3])
Answer: B
List slicing [1:3] returns elements from index 1 (inclusive) to index 3 (exclusive), which are elements at positions 1 and 2.
Q.105Medium
What is the output of: len([1, [2, 3], 4, [5, [6, 7]]])?
Answer: B
len() counts the number of top-level elements in the list: 1, [2,3], 4, and [5,[6,7]] = 4 elements total.
Advertisement
Q.106Medium
Which statement correctly creates a list of numbers from 1 to 5?
Answer: D
range(1, 6) generates 1 to 5 (exclusive end), and explicit list [1,2,3,4,5] both work. Both statements are correct.
Q.107Medium
What will be printed?
my_list = [10, 20, 30]
my_list[1] = 25
print(my_list)
Answer: B
Lists are mutable. Assignment my_list[1] = 25 changes the element at index 1 from 20 to 25.
Q.108Medium
Which of the following will return True?
my_list = [1, 2, 3]
result = 2 in my_list
Answer: A
The 'in' operator checks membership. Since 2 exists in my_list, the expression evaluates to True.
Q.109Medium
What is the difference between list and tuple in Python?
Answer: A
Lists (created with []) can be modified after creation, while tuples (created with ()) cannot be changed after initialization.
Q.110Medium
What will be the output?
my_list = [1, 2, 3]
my_list.extend([4, 5])
print(my_list)
Answer: B
extend() unpacks the iterable and adds individual elements. append() would add the list as a single element.
Q.111Medium
How many times will the value 2 appear in the output?
my_list = [1, 2, 2, 3, 2, 4]
print(my_list.count(2))
Answer: C
count() returns the number of occurrences of a value. The value 2 appears 3 times in the list.
Q.112Medium
What will be the output?
my_list = [[1, 2], [3, 4], [5, 6]]
print(my_list[1][0])
Answer: B
my_list[1] returns [3, 4], and [3, 4][0] returns 3 (first element of the nested list).
Q.113Medium
What will this code produce?
my_list = [3, 1, 4, 1, 5]
my_list.sort()
print(my_list)
Answer: B
sort() arranges list elements in ascending order by default. It modifies the list in-place.
Q.114Hard
What will be the output?
my_list = [1, 2, 3]
my_list_copy = my_list
my_list[0] = 99
print(my_list_copy[0])
Answer: B
Assignment creates a reference, not a copy. Both variables point to the same list object, so changes are reflected in both.
Q.115Hard
What is the correct way to create a true copy of a list?
Answer: D
Both .copy() method and list() constructor create shallow copies. Simple assignment creates only a reference.
Q.116Hard
What will be the output?
my_list = [1, 2, 3, 4, 5]
print(my_list[-2])
Answer: C
Negative indexing starts from the end: -1 is 5, -2 is 4, -3 is 3, etc. So -2 returns 4.
Q.117Hard
What will be the result of executing this code?
my_list = [1, 2, 3]
my_list.insert(1, 99)
print(my_list)
Answer: A
insert(1, 99) inserts 99 at index 1, shifting existing elements right. Result is [1, 99, 2, 3].
Q.118Hard
What will be printed?
my_list = [1, 2, 3, 4, 5]
print(my_list[::-1])
Answer: A
Slice [::-1] reverses the list by using step -1 (backwards through entire list). It returns a reversed copy.
Q.119Medium
What will be the output of the following code?
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
return 'Some sound'
class Dog(Animal):
def speak(self):
return 'Woof'
d = Dog('Rex')
print(d.speak())
Answer: B
Dog overrides the speak() method of Animal. When speak() is called on a Dog instance, Python uses method resolution order (MRO) and finds speak() in Dog first, so it returns 'Woof'. This is an example of method overriding in inheritance.
Q.120Medium
Which of the following best describes the purpose of the __str__ method in a Python class?
Answer: B
__str__ is a dunder (magic) method that defines the human-readable string representation of an object. When you call print(obj) or str(obj), Python internally calls obj.__str__(). It is meant to be informative and readable for end users.