Python Questions March 20, 2023 | No Comments 0 votes, 0 avg 569 123456789101112131415 Python Questions 1 / 15 1. What will be the output of the following Python code? class test: def __init__(self,a): self.a=a def display(self): print(self.a) obj=test() obj.display() A. Runs normally, doesn’t display anything B. Displays 0, which is the automatic default value C. Error as one argument is required while creating the object D. Error as display function requires additional argument 2 / 15 2. What will be the output of the following code snippet? s1 = {1, 2, 3, 4, 5} s2 = {2, 4, 6} print(s1 ^ s2) A. {1, 2, 3, 4, 5} B. {1, 3, 5, 6} C. {2, 4} D. none of the above 3 / 15 3. What will be the output of the following Python code? a=[1,2,3] b=a.append(4) print(a) print(b) A. [1,2,3,4] [1,2,3,4] B. [1, 2, 3, 4] None C. Syntax error D. [1,2,3] [1,2,3,4] 4 / 15 4. 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 5 / 15 5. 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) 6 / 15 6. What will be the output of the following Python code? l=[1, 0, 2, 0, 'hello', '', []] list(filter(bool, l)) A. [1, 0, 2, ‘hello’, ”, []] B. Error C. [1, 2, ‘hello’] D. [1, 0, 2, 0, ‘hello’, ”, []] 7 / 15 7. The % operator returns the ___. A. Quotient B. Divisor C. Remainder D. None of the mentioned above 8 / 15 8. 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 9 / 15 9. What will be the output of the following Python code? class tester: def __init__(self, id): self.id = str(id) id="224" >>>temp = tester(12) >>>print(temp.id) A. 12 B. 224 C. None D. Error 10 / 15 10. What will be the output of the following Python code? a=[13,56,17] a.append([87]) a.extend([45,67]) print(a) A. [13, 56, 17, [87], 45, 67] B. [13, 56, 17, 87, 45, 67] C. [13, 56, 17, 87,[ 45, 67]] D. [13, 56, 17, [87], [45, 67]] 11 / 15 11. 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 12 / 15 12. Which of the following Boolean expressions is not logically equivalent to the other three? A. not(-6<0 or-6>10) B. -6>=0 and -6<=10 C. not(-6<10 or-6==10) D. not(-6>10 or-6==10) 13 / 15 13. Conditional statements are also known as ___ statements. A. Decision-making B. Array C. List D. None of the mentioned above 14 / 15 14. Which keyword is used for function in Python language? A. Function B. def C. Fun D. Define 15 / 15 15. Which of these is the definition for packages in Python? A. A set of main modules B. A folder of python modules C. A number of files containing Python definitions and statements D. A set of programs making use of Python modules Your score isThe average score is 37% LinkedIn Facebook VKontakte 0% Restart quiz By WordPress Quiz plugin Questions, Quiz