a) <class ‘list’> b) <class ‘tuple’> c) <class ‘set’> d) Error
Correct Answer: a) <class 'list'>
Explanation: An empty list is denoted by [], and its type is <class 'list'>.
Question 32
What is the result of this Python code?
print([1, 2] + [3, 4])
a) [1, 2, 3, 4] b) [3, 4] c) [1, 2] d) Error
Correct Answer: a) [1, 2, 3, 4]
Explanation: The + operator concatenates two lists. [1, 2] + [3, 4] results in [1, 2, 3, 4].
Question 33
What does this Python code output?
x = (1, 2, 3)
print(len(x))
a) 1 b) 2 c) 3 d) Error
Correct Answer: c) 3
Explanation: The len() function returns the number of elements in a tuple. The tuple (1, 2, 3) has three elements.
Question 34
What will this Python code return?
x = set([1, 2, 2, 3])
print(x)
a) {1, 2, 2, 3} b) {1, 2, 3} c) [1, 2, 3] d) Error
Correct Answer: b) {1, 2, 3}
Explanation: A set contains only unique elements. Duplicates are removed automatically.
Question 35
What does this Python code return?
print(“Python”.endswith(“n”))
a) True b) False c) Error d) None
Correct Answer: a) True
Explanation: The endswith() method checks whether a string ends with the specified suffix. "Python".endswith("n") returns True.
Question 36
What will be the output of this Python code?
x = [1, 2, 3]
y = [1, 2, 3]
print(x is y)
a) True b) False c) Error d) None
Correct Answer: b) False
Explanation: The is operator checks whether two variables point to the same object in memory. In this case, x and y refer to different list objects, so x is y returns False.
Question 37
What does this Python code return?
x = (1, 2, 3)
y = (1, 2, 3)
print(x == y)
a) True b) False c) Error d) None
Correct Answer: a) True
Explanation: The == operator checks whether two variables have the same value. Since both tuples have the same values, the result is True.
Question 38
What will this Python code output?
x = {“a”: 1, “b”: 2}
print(x[“a”])
a) 1 b) 2 c) “a” d) Error
Correct Answer: a) 1
Explanation: The value associated with the key "a" in the dictionary is 1.
Question 39
What does this Python code return?
print(len({1, 2, 3}))
a) 1 b) 2 c) 3 d) 4
Correct Answer: c) 3
Explanation: The len() function returns the number of elements in the set {1, 2, 3}, which is 3.
Question 40
What will this Python code output?
x = [1, 2, 3]
print(x[-1])
a) 1 b) 2 c) 3 d) Error
Correct Answer: c) 3
Explanation: Negative indexing in Python allows you to access elements from the end of a list. x[-1] refers to the last element, which is 3.