Python QuestionsBy Kritika Papne / March 20, 2023 0 votes, 0 avg 719 123456789101112131415 Python Questions 1 / 15 1. 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 2 / 15 2. Set makes use of __________ Dictionary makes use of ____________ A. keys, keys B. key values, keys C. keys, key values D. key values, key values 3 / 15 3. What keyword is used in Python to throw exceptions? A. raise B. try C. goto D. except 4 / 15 4. What will be the output of the following code snippet? a = "4, 5" nums = a.split(',') x, y = nums int_prod = int(x) * int(y) print(int_prod) A. 20 B. 45 C. 54 D. 4, 5 5 / 15 5. Is Python code compiled or interpreted? A. Python code is both compiled and interpreted B. Python code is neither compiled nor interpreted C. Python code is only compiled D. Python code is only interpreted 6 / 15 6. 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 7 / 15 7. Which of the following are valid escape sequences in Python? A. n B. t C. \ D. all of the above 8 / 15 8. What will be the output of the following Python program? z=set('abc') z.add('san') z.update(set(['p', 'q'])) Z A. {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’} B. {‘abc’, ‘p’, ‘q’, ‘san’} C. {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’} D. {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san} 9 / 15 9. What will be the output of the following Python code? x = 50 def func(x): print('x is', x) x = 2 print('Changed local x to', x) func(x) print('x is now', x) A. x is 50 Changed local x to 2 x is now 50 B. x is 50 Changed local x to 2 x is now 2 C. x is 50 Changed local x to 2 x is now 100 D. None of the mentioned 10 / 15 10. What will be the output of the following Python code? for i in range(5): if i == 5: break else: print(i) else: print("Here") A. 0 1 2 3 4 Here B. 0 1 2 3 4 5 Here C. 0 1 2 3 4 D. 1 2 3 4 5 11 / 15 11. What will be the output of the following Python code? def func(a, b=5, c=10): print('a is', a, 'and b is', b, 'and c is', c) func(3, 7) func(25, c = 24) func(c = 50, a = 100) A. a is 7 and b is 3 and c is 10 a is 25 and b is 5 and c is 24 a is 5 and b is 100 and c is 50 B. a is 3 and b is 7 and c is 10 a is 5 and b is 25 and c is 24 a is 50 and b is 100 and c is 5 C. a is 3 and b is 7 and c is 10 a is 25 and b is 5 and c is 24 a is 100 and b is 5 and c is 50 D. None of the mentioned 12 / 15 12. Which of the following functions can be used to read data from a file using a file descriptor? A. os.reader() B. os.read() C. os.quick_read() D. os.scan() 13 / 15 13. 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) 14 / 15 14. To add a new element to a list we use which Python command? A. list1.addEnd(5) B. list1.addLast(5) C. list1.append(5) D. list1.add(5) 15 / 15 15. What is the order of namespaces in which Python looks for an identifier? A. Python first searches the built-in namespace, then the global namespace and finally the local namespace B. Python first searches the built-in namespace, then the local namespace and finally the global namespace C. Python first searches the local namespace, then the global namespace and finally the built-in namespace D. Python first searches the global namespace, then the local namespace and finally the built-in namespace Your score isThe average score is 40% LinkedIn Facebook VKontakte 0% Restart quiz By WordPress Quiz plugin Written by Shubhranshu Shekhar, who has trained 20000+ students in coding. Kritika Papne