Python Programming Quiz

Quiz on Class in Python

Time left: 300 seconds

Q.1. In Python, a class is ___________ for a concrete object.

Select Your Option

It is the definition of a class

Q.2. How to create a constructor in python?

Select Your Option

The __init__() method is called the constructor and it is always called when an object is created in Python.

Q.3. If a properties of two classes are derived into one then it is called

Select Your Option

Mulitple inheritance is the type of inheritance where 1 class is derived from the properties of 2 base classes

Q.4. Which keyword is used to declare a class?

Select Your Option

'class' is a reserved keyword in Python. It is used to declare classes.

Q.5. What will be the output of the following code snippet?
          
            class Employee:
                def __init__(self, id):
                    self.id = id

            e = Employee(123)
            print(e.id)
          
          

Select Your Option

123 is passed to the constructor when the object e of Employee class is created. Within the constructor, the value 123 is then assigned to local variable id of the class.

Q.6. what is numpy in below line
          
            import numpy as np
          
          

Select Your Option

numpy is a Python library which is used for working with arrays. Here, the import statement searches for the module and makes the module code available in our file.

Q.7. What method is used to invoke a parent constructor from child class?

Select Your Option

super() is a built-in function that gives access to the methods and properties of a parent class when called from the child class.

Q.8.If properties of class is derived into two or more classes then is it called

Select Your Option

In Hierarchical inheritance, muliple child class are derived from 1 base class.

Q.9. What is setattr() used for?

Select Your Option

setattr() is a function that sets the value of the attribute of an object.

Q.10. What is dist in below line?
          
            from math import dist
          
          

Select Your Option

In given statement, we are importing a particular class (dist) from a module (math).

Q.11. What will the list contain in following program?
          
            class Test:
                def __init__(self,n):
                    pass
            l=[]
            for i in range(5):
                l.append(Test(i))
            print(l)
          
          

Select Your Option

For i through 0 to 4, a new object of class Test is appended in the list. Hence, the list will contain 5 objects of the Test class.

Q.12. What will be the output of the following code snippet:
          
            class Test:
                def __init__(self,n):
                    self.n = n
                def area(self):
                    print(self.n*self.n)
            t = Test(5)
            t.area()
          
          

Select Your Option

5 is passed to the constructor of Test class when the object t is created. Inside the constructor, the value 5 is assigned to variable n of the class Test which is then squared and printed in the area() method.

Q.13. How can we check whether an object is an instance of a class?

Select Your Option

isinstance() is a function that returns True if the object is of specified type otherwise it returns False.

Q.14. If a class C inherits from two other classes A and B (in order - A, B) and a super method is used to invoke constructor of parent then the constructor invoked is of

Select Your Option

Python looks at the first class mentioned while inheriting in the child class. Since, given order is A,B - Python will first check the first class (ie, A) to see if it has the constructor defined, if it is defined, then it will execute that constructor. If the constructor is not defined in the first class, then Python will check the second class. Here, the order of inheritance matters to check which base class constructor will execute.

Q.15. The functions defined inside the class are called

Select Your Option

While a function returns a value, a procedure does not. A method is similar to a function but it is defined inside a class.

Instructions:-

  1. This Quiz is based on Dictionary in Python
  2. Each correct answer will carry 2 points
  3. Once an option is selected you cannot select any other, So choose wisely
  4. Do not refresh the page as it will reset the quiz
  5. Once the time is up the quiz will automatically get submitted with no of Question responded
  6. Your total score alongwith your name will be shown after submission of the Quiz
  7. Wish you ALL THE BEST 👍👍

START

Results:-

Hi




Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post