Python QuestionsBy Kritika Papne / March 20, 2023 0 votes, 0 avg 686 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. 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. 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 4 / 15 4. 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 5 / 15 5. 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 6 / 15 6. Which of the following blocks will always be executed whether an exception is encountered or not in a program? A. try B. except C. finally D. none of the above 7 / 15 7. What is the order of precedence in python? A. Exponential, Parentheses, Multiplication, Division, Addition, Subtraction B. Exponential, Parentheses, Division, Multiplication, Addition, Subtraction C. Parentheses, Exponential, Multiplication, Division, Subtraction, Addition D. Parentheses, Exponential, Multiplication, Division, Addition, Subtraction 8 / 15 8. What will be the output of the following Python code? x = "abcdef" i = "a" while i in x: x = x[:-1] print(i, end = " ") A. i i i i i i B. a a a a a a C. a a a a a D. none of the mentioned 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 Python code? print('abcdef'.partition('cd')) A. (‘ab’, ‘ef’) B. (‘abef’) C. (‘ab’, ‘cd’, ‘ef’) D. 2 11 / 15 11. Set makes use of __________ Dictionary makes use of ____________ A. keys, keys B. key values, keys C. keys, key values D. key values, key values 12 / 15 12. Which of the following is the proper syntax to check if a particular element is present in a list? A. if ele in list B. if not ele not in list C. none of the mentioned D. Both A and B 13 / 15 13. Which of the following expressions can be used to multiply a given number ‘a’ by 4? A. a<<2 B. a<<4 C. a>>2 D. a>>4 14 / 15 14. Which keyword is used for function in Python language? A. Function B. def C. Fun D. Define 15 / 15 15. 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__() 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