Which method is used to get the index of an element in a list?
a) find() b) index() c) search() d) position()
Correct Answer: b) index()
Explanation: The index() method returns the index of the first occurrence of an element in a list.
Question 42
What is the result of this Python expression?
not True and False
a) True b) False c) None d) Error
Correct Answer: b) False
Explanation: According to Boolean logic, not True is False, and False and False is False.
Question 43
Which keyword is used to handle exceptions in Python?
a) except b) error c) try d) handle
Correct Answer: c) try
Explanation: The try keyword is used to start a block of code that might raise an exception. If an exception occurs, it is handled by the except block.
Question 44
What is the output of this Python code?
print(len(“Python”))
a) 5 b) 6 c) 7 d) Error
Correct Answer: b) 6
Explanation: The string "Python" contains 6 characters, so len("Python") returns 6.
Question 45
What does the pop() method do in Python?
a) Removes the first element of the list b) Removes the last element of the list c) Returns the last element without removing it d) Removes an element by its value
Correct Answer: b) Removes the last element of the list
Explanation: The pop() method removes and returns the last element of the list.
Question 46
Which of the following is a valid function definition in Python?
a) def myFunc {} b) function myFunc() c) def myFunc(): d) function myFunc {}
Correct Answer: c) def myFunc():
Explanation: A function in Python is defined using the def keyword followed by the function name and parentheses, with a colon at the end.
Question 47
Which of the following will create an empty list?
a) list() b) [] c) {} d) Both a and b
Correct Answer: d) Both a and b
Explanation: Both list() and [] can be used to create an empty list in Python.
Question 48
How can you concatenate two tuples in Python?
a) + b) * c) append() d) extend()
Correct Answer: a) +
Explanation: You can concatenate two tuples using the + operator.
Question 49
What will be the output of the following Python code?
x = [1, 2, 3]
y = x
y.append(4)
print(x)
a) [1, 2, 3] b) [1, 2, 3, 4] c) [1, 2] d) [4]
Correct Answer: b) [1, 2, 3, 4]
Explanation: Since y refers to the same list as x, appending to y will also modify x.
Question 50
What is the result of this Python expression?
5 // 2
a) 2 b) 2.5 c) 1 d) 3
Correct Answer: a) 2
Explanation: The // operator performs floor division, which divides and rounds down to the nearest integer. 5 // 2 equals 2.