Python Questions March 20, 2023 | No Comments 0 votes, 0 avg 606 123456789101112131415 Python Questions 1 / 15 1. What will be the output of the following program? i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0) A. 1 2 3 B. 0 1 2 3 C. 0 1 2 D. 3 2 1 2 / 15 2. Which function is called when the following Python program is executed? f = foo() format(f) A. str() B. format() C. __str__() D. __format__() 3 / 15 3. 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 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. What is called when a function is defined inside a class? A. Module B. Class C. Another Function D. Method 6 / 15 6. 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 7 / 15 7. What will be the output of the following code snippet? def thrive(n): if n % 15 == 0: print("thrive", end = “ ”) elif n % 3 != 0 and n % 5 != 0: print("neither", end = “ ”) elif n % 3 == 0: print("three", end = “ ”) elif n % 5 == 0: print("five", end = “ ”) thrive(35) thrive(56) thrive(15) thrive(39) A. five neither three thrive B. five neither thrive three C. three three three three D. five neither five neither 8 / 15 8. 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 9 / 15 9. 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 10 / 15 10. What will be the output of the following Python code? l=list('HELLO') p=l[0], l[-1], l[1:3] 'a={0}, b={1}, c={2}'.format(*p) A. Error B. “a=’H’, b=’O’, c=(E, L)” C. “a=H, b=O, c=[‘E’, ‘L’]” D. Junk value 11 / 15 11. What will be the datatype of the var in the below code snippet? var = 10 print(type(var)) var = "Hello" print(type(var)) A. str and int B. int and int C. str and str D. int and str 12 / 15 12. 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 13 / 15 13. Set makes use of __________ Dictionary makes use of ____________ A. keys, keys B. key values, keys C. keys, key values D. key values, key values 14 / 15 14. Which of the following is not a valid set operation in python? A. Union B. Intersection C. Difference D. none of the above 15 / 15 15. In Python, the break and continue statements, together are called ___ statement. A. Jump B. goto C. compound D. None of the mentioned above Your score isThe average score is 37% LinkedIn Facebook VKontakte 0% Restart quiz By WordPress Quiz plugin Written by Shubhranshu Shekhar, who has trained 20000+ students in coding. Kritika Papne Questions, Quiz