OA Exams
What is the output of print(type({}))?
a) setb) dictc) listd) None
Correct Answer: b) dict
Explanation: An empty pair of curly braces {} creates an empty dictionary in Python.
What is the function of the ord() method?
a) Returns the Unicode point for a characterb) Converts a string to lowercasec) Reverses a stringd) Finds the length of a string
Correct Answer: a) Returns the Unicode point for a character
Explanation: The ord() method returns the Unicode code point of a single character.
Which of the following is not a Python built-in function?
a) print()b) input()c) map()d) clear()
Correct Answer: d) clear()
Explanation: clear() is a method for certain data types like dictionaries and sets, but not a built-in function.
How do you convert an integer to a string in Python?
a) str()b) int()c) float()d) repr()
Correct Answer: a) str()
Explanation: The str() function converts any data type to a string.
What is the result of print(4 / 2)?
a) 2b) 2.0c) 4d) Error
Correct Answer: b) 2.0
Explanation: Division / in Python always returns a float, even if the result is a whole number.
Which of the following functions can be used to create a new tuple?
a) list()b) set()c) tuple()d) dict()
Correct Answer: c) tuple()
Explanation: The tuple() function is used to create a new tuple in Python.
What is the default value of the start parameter in the range() function?
a) 1b) 0c) -1d) None
Correct Answer: b) 0
Explanation: The start parameter in range() defaults to 0, meaning the sequence starts at 0 unless otherwise specified.
Which of the following is true about Python lists?
a) Lists are immutableb) Lists are ordered collectionsc) Lists cannot contain duplicatesd) Lists must only contain integers
Correct Answer: b) Lists are ordered collections
Explanation: Lists in Python are ordered, meaning the elements are indexed and maintain the order in which they were added.
How do you access the last element of a list in Python?
a) list[-1]b) list[0]c) list[1]d) list[len(list)]
Correct Answer: a) list[-1]
Explanation: The index -1 refers to the last element in a list in Python.
Which of the following is not a valid Python loop control structure?
a) forb) whilec) do-whiled) break
Correct Answer: c) do-while
Explanation: Python does not have a do-while loop; it only supports for and while loops.