OA Exams
Which operator is used to get the remainder of a division in Python?
a) /b) %c) **d) //
Correct Answer: b) %
Explanation: The modulus operator % returns the remainder of a division.
What does str(5) return in Python?
a) The string ‘5’b) The integer 5c) The float 5.0d) The list [5]
Correct Answer: a) The string '5'
Explanation: The str() function converts an integer or float to a string.
Which method can be used to convert a string to lowercase in Python?
a) upper()b) capitalize()c) lower()d) title()
Correct Answer: c) lower()
Explanation: The lower() method converts all characters in a string to lowercase.
Which keyword is used to handle exceptions in Python?
a) tryb) throwc) exceptd) finally
Correct Answer: c) except
Explanation: The except keyword is used to handle exceptions in Python.
What will be the output of print(4 % 2)?
a) 2b) 0c) 1d) 4
Correct Answer: b) 0
Explanation: 4 % 2 returns 0 because 4 is divisible by 2 with no remainder.
Which function in Python generates a range of numbers?
a) range()b) list()c) tuple()d) len()
Correct Answer: a) range()
Explanation: The range() function generates a sequence of numbers.
What is the output of the following code: print(10 // 3)?
a) 3.0b) 3c) 3.33d) 4
Correct Answer: b) 3
Explanation: // is the floor division operator, which returns the largest integer less than or equal to the division result.
Which method would you use to convert a string to an integer in Python?
a) str()b) int()c) float()d) bool()
Correct Answer: b) int()
Explanation: The int() method converts a valid string or float to an integer.
What is the purpose of the elif statement in Python?
a) To check multiple conditionsb) To end a loopc) To start a new block of coded) To convert data types
Correct Answer: a) To check multiple conditions
Explanation: The elif statement allows the program to test multiple conditions in an if-elif-else structure.
Which keyword is used to define a class in Python?
a) defb) classc) objectd) new
Correct Answer: b) class
Explanation: The class keyword is used to define a class in Python, which is a blueprint for creating objects.