| Snaprecruit.com

| Snaprecruit.com

Interview question based on skill :

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. What happens if a local variable exists with the same name as the global variable you want to access?

Correct Answer is : The global variable is shadowed

2. What is the output of the code shown below? a=10 globals()['a']=25 print(a)

Correct Answer is : 25

3. What is the output of this code? def f(): x=4 x=1 f() x

Correct Answer is : 1

4. ______________ returns a dictionary of the module namespace. ________________ returns a dictionary of the current namespace.

Correct Answer is : globals()

5. Which of the following best describes inheritance?

Correct Answer is : Ability of a class to derive members of another class as a part of its own definition

6. Which of the following statements is wrong about inheritance?

Correct Answer is : Private members of a class can be inherited and accessed

7. What is the output of the following 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()

Correct Answer is : Derived_Demo’s __new__() invoked Demo’s __init__() invoked Demo’s __new__() invoked

8. What is the output of the following piece of code? class Test: def __init__(self): self.x = 0 class Derived_Test(Test): def __init__(self): self.y = 1 def main(): b = Derived_Test() print(b.x,b.y) main()

Correct Answer is : Error because class B inherits A but variable x isn’t inherited

9. What is the output of the following piece of code? class A(): def disp(self): print("A disp()") class B(A): pass obj = B() obj.disp()

Correct Answer is : A disp()

10. All subclasses are a subtype in object-oriented programming. Is the statement true or false?

Correct Answer is : FALSE

11. When defining a subclass in Python that is meant to serve as a subtype, the subtype Python keyword is used. Is the statement true or false?

Correct Answer is : FALSE

12. Suppose B is a subclass of A, to invoke the __init__ method in A from B, what is the line of code you should write?

Correct Answer is : A.__init__(self)

13. What is the output of the following piece of code? class Test: def __init__(self): self.x = 0 class Derived_Test(Test): def __init__(self): Test.__init__(self) self.y = 1 def main(): b = Derived_Test() print(b.x,b.y) main()

Correct Answer is : 0 1

14. What is the output of the following piece of code? class A: def __init__(self, x= 1): self.x = x class der(A): def __init__(self,y = 2): super().__init__() self.y = y def main(): obj = der() print(obj.x, obj.y) main()

Correct Answer is : 45293

15. What does built-in function type do in context of classes?

Correct Answer is : Determines the class name of any value

16. Which of the following is not a type of inheritance?

Correct Answer is : Double-level

17. What does built-in function help do in context of classes?

Correct Answer is : Determines class description of any built-in type

18. What is the output of the following piece of code? class A: def one(self): return self.two()   def two(self): return 'A'   class B(A): def two(self): return 'B' obj1=A() obj2=B() print(obj1.two(),obj2.two())

Correct Answer is : A B

19. What type of inheritance is illustrated in the following piece of code? class A(): pass class B(): pass class C(A,B): pass

Correct Answer is : Multiple inheritance

20. What type of inheritance is illustrated in the following piece of code? class A(): pass class B(A): pass class C(B): pass

Correct Answer is : Multi-level inheritance