OA Exams
What will be the output of print(‘hello’.upper())?
a) HELLOb) helloc) Hellod) Error
Correct Answer: a) HELLO
Explanation: The upper() method converts all characters in a string to uppercase.
What does the pass statement do in Python?
a) Stops the execution of a loopb) Does nothing and continues to the next statementc) Skips the current iteration of a loopd) Terminates a function
Correct Answer: b) Does nothing and continues to the next statement
Explanation: The pass statement is used as a placeholder and does not perform any action.
What is the result of print(7 // 3)?
a) 2b) 2.33c) 1d) 3
Correct Answer: a) 2
Explanation: The // operator performs floor division and returns the largest integer less than or equal to the result.
Which method is used to reverse a list in Python?
a) reverse()b) reversed()c) flip()d) sort(reverse=True)
Correct Answer: a) reverse()
Explanation: The reverse() method reverses the elements of a list in place.
How do you delete an element from a dictionary in Python?
a) del dict[key]b) dict.delete(key)c) dict.remove(key)d) remove dict[key]
Correct Answer: a) del dict[key]
Explanation: The del statement removes the key-value pair from a dictionary.
What will be the result of print(10 % 3)?
a) 3b) 1c) 10d) 0
Correct Answer: b) 1
Explanation: The modulus operator % returns the remainder of a division, so 10 % 3 equals 1.
Which operator is used to check if two values are not equal in Python?
a) !=b) ==c) <>d) ><
Correct Answer: a) !=
Explanation: The != operator checks if two values are not equal.
How do you create a multi-line comment in Python?
a) Using # for each lineb) Using “”” or ”’c) Using /* */d) Using //
Correct Answer: b) Using """ or '''
Explanation: Multi-line comments are created using triple quotes, either """ or '''.
What is the purpose of the break statement in a loop?
a) To skip the current iterationb) To exit the loop immediatelyc) To continue to the next iterationd) To restart the loop
Correct Answer: b) To exit the loop immediately
Explanation: The break statement causes the loop to terminate immediately, regardless of its condition.
What is the result of 5 + 3 * 2 in Python?
a) 16b) 11c) 10d) 13
Correct Answer: b) 11
Explanation: According to operator precedence, multiplication is performed before addition, so 3 * 2 is evaluated first, followed by 5 + 6.