Python Questions March 20, 2023 | No Comments 0 votes, 0 avg 39 123456789101112131415 Python Questions 1 / 15 1. What will be the output of the following code snippet? a = 3 b = 1 print(a, b) a, b = b, a print(a, b) A. 1 3 3 1 B. 1 3 1 3 C. 3 1 3 1 D. 3 1 1 3 2 / 15 2. Python supports the creation of anonymous functions at runtime, using a construct called __________ A. pi B. anonymous C. lambda D. None of the mentioned 3 / 15 3. What will be the output of the following Python program? def addItem(listParam): listParam += [1] mylist = [1, 2, 3, 4] addItem(mylist) print(len(mylist)) A. 5 B. 2 C. 8 D. 1 4 / 15 4. What is Instantiation in terms of OOP terminology? A. Deleting an instance of class B. Modifying an instance of class C. Copying an instance of class D. Creating an instance of class 5 / 15 5. What will be the output of the following Python code? def C2F(c): return c * 9/5 + 32 print C2F(100) print C2F(0) A. 212 32 B. 314 24 C. 567 98 D. None of the mentioned 6 / 15 6. Which of the following best describes inheritance? A. Ability of a class to derive members of another class as a part of its own definition B. Means of bundling instance variables and methods in order to restrict access to certain class members C. Focuses on variables and passing of variables to functions D. Allows for implementation of elegant software that is well designed and easily modified 7 / 15 7. Which of the following Python code will print True? a = foo(2) b = foo(3) print(a < b) A. class foo: def __init__(self, x): self.x = x def __lt__(self, other): if self.x < other.x: return False else: return True B. class foo: def __init__(self, x): self.x = x def __less__(self, other): if self.x > other.x: return False else: return True C. class foo: def __init__(self, x): self.x = x def __lt__(self, other): if self.x < other.x: return True else: return False D. class foo: def __init__(self, x): self.x = x def __less__(self, other): if self.x < other.x: return False else: return True 8 / 15 8. Which of these about a frozenset is not true? A. Mutable data type B. Allows duplicate values C. Data type with unordered values D. Immutable data type 9 / 15 9. What happens if the file is not found in the following Python code? a=False while not a: try: f_n = input("Enter file name") i_f = open(f_n, 'r') except: print("Input file not found") A. No error B. Assertion error C. Input output error D. Name error 10 / 15 10. Consider the results of a medical experiment that aims to predict whether someone is going to develop myopia based on some physical measurements and heredity. In this case, the input dataset consists of the person’s medical characteristics and the target variable is binary: 1 for those who are likely to develop myopia and 0 for those who aren’t. This can be best classified as A. Regression B. Decision Tree C. Clustering D. Association Rules 11 / 15 11. In Python, ___ defines a block of statements. A. Block B. Loop C. Indentation D. None of the mentioned above 12 / 15 12. Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed? A. __add__(), __str__() B. __str__(), __add__() C. __sum__(), __str__() D. __str__(), __sum__() 13 / 15 13. What keyword is used in Python to throw exceptions? A. raise B. try C. goto D. except 14 / 15 14. Which of the following counts the number of elements in Numpy array ? A. count() B. return() C. shape() D. size() 15 / 15 15. What will be the output of the following Python code? string = "my name is x" for i in string.split(): print (i, end=", ") A. m, y, , n, a, m, e, , i, s, , x, B. m, y, , n, a, m, e, , i, s, , x C. my, name, is, x, D. error Your score is The average score is 34% LinkedIn Facebook Twitter VKontakte 0% Restart quiz Questions, Quiz