OA Exams
What will print(10 // 3) output in Python?
a) 3b) 3.33c) 3.0d) 4
Correct Answer: a) 3
Explanation: The // operator performs floor division, which returns the largest integer less than or equal to the result of the division.
Which of the following creates an empty list in Python?
a) list = ()b) list = []c) list = {}d) list = set()
Correct Answer: b) list = []
Explanation: An empty list is created using square brackets [].
What is the output of print(‘hello’.upper()) in Python?
a) hellob) HELLOc) Hellod) HeLLo
Correct Answer: b) HELLO
Explanation: The upper() method converts all characters of a string to uppercase.
Which method is used to combine the contents of two dictionaries in Python?
a) dict.add()b) dict.update()c) dict.concat()d) dict.join()
Correct Answer: b) dict.update()
Explanation: The update() method adds key-value pairs from one dictionary to another.
What will print([1, 2, 3] + [4, 5]) output in Python?
a) [1, 2, 3, 4, 5]b) [1, 2, 3]c) [4, 5]d) [1, 2, 3, [4, 5]]
Correct Answer: a) [1, 2, 3, 4, 5]
Explanation: Using + concatenates two lists into a single list.
What is the correct syntax for defining a function in Python?
a) def function_name:b) function function_name:c) def function_name():d) func function_name():
Correct Answer: c) def function_name():
Explanation: Functions in Python are defined using the def keyword followed by the function name and parentheses ().
How do you add a single element to a set in Python?
a) set.add()b) set.append()c) set.insert()d) set.extend()
Correct Answer: a) set.add()
Explanation: The add() method adds a single element to a set.
What is the correct way to check if an element is in a list in Python?
a) element in listb) list.has(element)c) element.contains(list)d) list.exists(element)
Correct Answer: a) element in list
Explanation: The in keyword checks if an element exists in a list.
Which of the following is a tuple in Python?
a) {1, 2, 3}b) [1, 2, 3]c) (1, 2, 3)d) {{1, 2, 3}}
Correct Answer: c) (1, 2, 3)
Explanation: A tuple is defined using parentheses ().
What does the clear() method do for a list in Python?
a) Removes one element from the listb) Deletes the list from memoryc) Removes all elements from the listd) Reverses the list
Correct Answer: c) Removes all elements from the list
Explanation: The clear() method empties the list by removing all elements.
Which method can be used to combine all elements in a list into a single string?
a) concat()b) join()c) merge()d) append()
Correct Answer: b) join()
Explanation: The join() method concatenates the elements of a list into a single string, with a separator between each element.
How do you define a multi-line comment in Python?
a) // comment //b) /* comment */c) ”’ comment ”’d) ## comment ##
Correct Answer: c) ''' comment '''
Explanation: Multi-line comments in Python are written using triple quotes '''.
What is the output of print(type(42))?
a) intb) floatc) boold) str
Correct Answer: a) int
Explanation: The type() function returns the type of the object, and 42 is an integer.
How do you access the first element of a tuple t = (10, 20, 30)?
a) t[0]b) first()c) t(0)d) t[1]
Correct Answer: a) t[0]
Explanation: Tuples are indexed similarly to lists, and the first element has an index of 0.
Which operator is used to check if two values are the same object in memory?
a) ==b) !=c) isd) in
Correct Answer: c) is
Explanation: The is operator checks if two variables refer to the same object in memory.
What is the output of bool(None) in Python?
a) Trueb) Falsec) Noned) Error
Correct Answer: b) False
Explanation: None evaluates to False in a Boolean context.
How do you check if a list is empty in Python?
a) if list == Noneb) if len(list) == 0c) if not listd) Both b and c
Correct Answer: d) Both b and c
Explanation: You can check if a list is empty by using either len(list) == 0 or if not list, which evaluates to True if the list is empty.
What is the output of print(“abc” * 3)?
a) abcabcabcb) abc abc abcc) abc*3d) Error
Correct Answer: a) abcabcabc
Explanation: Multiplying a string by an integer repeats the string that many times.
Which of the following creates a dictionary in Python?
a) d = []b) d = {}c) d = ()d) d = [[]]
Correct Answer: b) d = {}
Explanation: An empty dictionary is created using curly braces {}.
What does the sorted() function do in Python?
a) Sorts a list in placeb) Returns a sorted listc) Sorts a dictionary by valuesd) Sorts elements in reverse
Correct Answer: b) Returns a sorted list
Explanation: The sorted() function returns a new list with elements in sorted order without modifying the original list.