Python Questions March 20, 2023 | No Comments 0 votes, 0 avg 543 123456789101112131415 Python Questions 1 / 15 1. 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 2 / 15 2. What will be the output of the following Python code if the input entered is 6? valid = False while not valid: try: n=int(input("Enter a number")) while n%2==0: print("Bye") valid = True except ValueError: print("Invalid") A. Bye (printed once) B. No output C. Invalid (printed once) D. Bye (printed infinite number of times) 3 / 15 3. What will be the output of the following code snippet? a = [1, 2, 3] a = tuple(a) a[0] = 2 print(a) A. [2,2,3] B. (2,2,3) C. (1,2,3) D. error 4 / 15 4. Which of the following is false regarding conditional statement in Python? A. If-elif is the shortcut for the if-else chain B. We use the dictionary to replace the Switch case statement C. We cannot use python classes to implement the switch case statement D. None of the mentioned above 5 / 15 5. Which of the following is the use of id() function in python? A. Id returns the identity of the object B. Every object doesn’t have a unique id C. All of the mentioned D. None of the mentioned 6 / 15 6. What will be the output of the following Python code? places = ['Bangalore', 'Mumbai', 'Delhi'] places1 = places places2 = places[:] places1[1]="Pune" places2[2]="Hyderabad" print(places) A. [‘Bangalore’, ‘Pune’, ‘Hyderabad’] B. [‘Bangalore’, ‘Pune’, ‘Delhi’] C. [‘Bangalore’, ‘Mumbai’, ‘Delhi’] D. [‘Bangalore’, ‘Mumbai’, ‘Hyderabad’] 7 / 15 7. 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 8 / 15 8. 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 9 / 15 9. Which of the following is true for variable names in Python? A. underscore and ampersand are the only two special characters allowed B. variable names can be of unlimited length C. all private members must have leading and trailing underscores D. All of the above 10 / 15 10. What will be the output of the following code snippet? numbers = (4, 7, 19, 2, 89, 45, 72, 22) sorted_numbers = sorted(numbers) even = lambda a: a % 2 == 0 even_numbers = filter(even, sorted_numbers) print(type(even_numbers)) A. int B. list C. filter D. tuple 11 / 15 11. Which of the following character is used to give single-line comments in Python? A. // B. # C. ! D. /* 12 / 15 12. The list.index(x[, start[, end]]) is used to ___. A. Return zero-based index in the list B. Raises a ValueError if there is no such item C. Both A and B D. None of the mentioned above 13 / 15 13. What will be the value of ‘result’ in following Python program? list1 = [1,2,3,4] list2 = [2,4,5,6] list3 = [2,6,7,8] result = list() result.extend(i for i in list1 if i not in (list2+list3) and i not in result) result.extend(i for i in list2 if i not in (list1+list3) and i not in result) result.extend(i for i in list3 if i not in (list1+list2) and i not in result) A. [1, 3, 5, 7, 8] B. [1, 7, 8] C. [1, 2, 4, 7, 8] D. error 14 / 15 14. Study the following program: class Std_Name: def __init__(self, Std_firstName, Std_Phn, Std_lastName): self.Std_firstName = Std_firstName self. Std_PhnStd_Phn = Std_Phn self. Std_lastNameStd_lastName = Std_lastName Std_firstName = "Wick" name = Std_Name(Std_firstName, 'F', "Bob") Std_firstName = "Ann" name.lastName = "Nick" print(name.Std_firstName, name.Std_lastName) What will be the output of the print statement? A. Ann Bob B. Ann Nick C. Wick Bob D. Wick Nick 15 / 15 15. 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 Your score isThe average score is 36% LinkedIn Facebook VKontakte 0% Restart quiz By WordPress Quiz plugin Questions, Quiz