OA Exams
What is the result of list(“hello”) in Python?
a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]b) [‘hello’]c) [hello]d) [‘h e l l o’]
Correct Answer: a) ['h', 'e', 'l', 'l', 'o']
Explanation: The list() function converts a string into a list of individual characters.
How do you retrieve all the keys from a dictionary in Python?
a) dict.keys()b) dict.values()c) dict.items()d) dict.get()
Correct Answer: a) dict.keys()
Explanation: The keys() method returns a view object containing all the keys of a dictionary.
Which operator is used to get the remainder of a division in Python?
a) /b) //c) %d) **
Correct Answer: c) %
Explanation: The % operator returns the remainder of a division
What will be the output of print(3 ** 2)?
a) 6b) 9c) 8d) Error
Correct Answer: b) 9
Explanation: The ** operator is used for exponentiation, and 3 ** 2 equals 9.
How do you convert a list of strings into a single string separated by commas?
a) ”.join(list)b) ‘,’.join(list)c) list.join(‘,’)d) string(list)
Correct Answer: b) ','.join(list)
Explanation: The join() method is used to concatenate list elements with a specified separator.
How do you find the minimum value in a list in Python?
a) min()b) max()c) sum()d) reduce()
Correct Answer: a) min()
Explanation: The min() function returns the smallest element in a list.
What is the result of len(“Hello World”)?
a) 10b) 11c) 12d) Error
Correct Answer: b) 11
Explanation: The len() function counts all characters in the string, including spaces, making it 11 characters long.
What is the default value of a global variable in Python?
a) 0b) Nonec) “”d) False
Correct Answer: b) None
Explanation: Global variables are initialized to None by default if not assigned a value.
Which of the following is not a valid list method in Python?
a) append()b) extend()c) insert()d) add()
Correct Answer: d) add()
Explanation: The add() method is used for sets, not lists.
What is the output of print(type([])) in Python?
a) setb) tuplec) listd) dict
Correct Answer: c) list
Explanation: An empty pair of square brackets [] creates an empty list in Python.
How do you remove the last element from a list in Python?
a) list.pop()b) list.remove()c) list.clear()d) list.delete()
Correct Answer: a) list.pop()
Explanation: The pop() method removes and returns the last element of a list.
What will print(range(5)) output in Python 3?
a) [0, 1, 2, 3, 4]b) range(0, 5)c) (0, 1, 2, 3, 4)d) Error
Correct Answer: b) range(0, 5)
Explanation: In Python 3, range() returns a range object, not a list.
How do you raise an exception in Python?
a) raise Exception(“Error”)b) throw Exception(“Error”)c) except Exception(“Error”)d) assert Exception(“Error”)
Correct Answer: a) raise Exception("Error")
Explanation: The raise statement is used to trigger an exception.
What is the output of print(“Hello”.replace(“l”, “L”))?
a) Hellob) HeLLoc) HeLLd) HELLO
Correct Answer: b) HeLLo
Explanation: The replace() method replaces all occurrences of the substring "l" with "L".
How do you declare a global variable inside a function in Python?
a) global xb) x = globalc) var xd) global(x)
Correct Answer: a) global x
Explanation: The global keyword is used to declare a global variable inside a function.
What is the result of print(len([]))?
a) 0b) Nonec) Errord) 1
Correct Answer: a) 0
Explanation: An empty list has a length of 0.
Which keyword is used to handle exceptions in Python?
a) exceptb) tryc) catchd) finally
Correct Answer: b) try
Explanation: The try block lets you test a block of code for exceptions.
What is the output of print(“A” in “Apple”)?
a) Trueb) Falsec) Noned) Error
Correct Answer: a) True
Explanation: The in operator checks if a substring exists within another string, and A is in "Apple".
What is the result of int(“42.5”)?
a) 42b) 42.5c) Errord) 43
Correct Answer: c) Error
Explanation: You cannot directly convert a string with a decimal point to an integer.
How do you concatenate two tuples in Python?
a) +b) append()c) extend()d) insert()
Correct Answer: a) +
Explanation: The + operator concatenates two tuples.