Python Questions March 20, 2023 | No Comments 0 votes, 0 avg 454 123456789101112131415 Python Questions 1 / 15 1. Which of the following are valid escape sequences in Python? A. n B. t C. \ D. all of the above 2 / 15 2. What will be the output of the following Python code? class Demo: def __new__(self): self.__init__(self) print("Demo's __new__() invoked") def __init__(self): print("Demo's __init__() invoked") class Derived_Demo(Demo): def __new__(self): print("Derived_Demo's __new__() invoked") def __init__(self): print("Derived_Demo's __init__() invoked") def main(): obj1 = Derived_Demo() obj2 = Demo() Main() A. Derived_Demo’s __init__() invoked Derived_Demo’s __new__() invoked Demo’s __init__() invoked Demo’s __new__() invoked B. Derived_Demo’s __new__() invoked Demo’s __init__() invoked Demo’s __new__() invoked C. Derived_Demo’s __new__() invoked Demo’s __new__() invoked D. Derived_Demo’s __init__() invoked Demo’s __init__() invoked 3 / 15 3. 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) 4 / 15 4. Which of the following is used to define a block of code in Python language? A. Indentation B. Keys C. Brackets D. All of the above 5 / 15 5. 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 6 / 15 6. What is Instantiation in terms of OOP terminology? A. Deleting an instance of class B. Modifying an instance of class C. Copying an instance of class D. Creating an instance of class 7 / 15 7. As what datatype are the *args stored, when passed into a function? A. list B. tuple C. dictionary D. none of the above 8 / 15 8. 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 9 / 15 9. 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 10 / 15 10. Which of the following is a feature of DocString? A. Provide a convenient way of associating documentation with Python modules, functions, classes, and methods B. All functions should have a docstring C. Docstrings can be accessed by the __doc__ attribute on objects D. All of the mentioned 11 / 15 11. 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() 12 / 15 12. The following python program can work with ____ parameters. def f(x): def f1(*args, **kwargs): print("JAVA") return x(*args, **kwargs) return f1 A. any number of B. O C. 1 D. 2 13 / 15 13. In Python, ___ defines a block of statements. A. Block B. Loop C. Indentation D. None of the mentioned above 14 / 15 14. What keyword is used in Python to throw exceptions? A. raise B. try C. goto D. except 15 / 15 15. 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 Your score is The average score is 35% LinkedIn Facebook Twitter VKontakte 0% Restart quiz Questions, Quiz