My Report

Python Programming Practice Test 10


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What type of inheritance is illustrated in the following Python code?

class A():
    pass
class B():
    pass
class C(A,B):
    pass

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

3. Which of the following statements is true?

4. Which of the following statements isn’t true?

5. What will be the output of the following Python code?

class test:
    def __init__(self):
        self.variable = 'Old'
        self.Change(self.variable)
    def Change(self, var):
        var = 'New'
obj=test()
print(obj.variable)

6. What will be the output of the following Python code?

class A:
    def __init__(self):
        self.multiply(15)
    def multiply(self, i):
        self.i = 4 * i;
class B(A):
    def __init__(self):
        super().__init__()
        print(self.i)
        
    def multiply(self, i):
        self.i = 2 * i;
obj = B()

7. Which function overloads the >> operator?

8. What will be the output of the following Python code?

class Demo:
    def __check(self):
        return " Demo's check "
    def display(self):
        print(self.check())
class Demo_Derived(Demo):
    def __check(self):
        return " Derived's check "
Demo().display()
Demo_Derived().display()

9. What will be the output of the following Python code?

class fruits:
    def __init__(self, price):
        self.price = price
obj=fruits(50)

obj.quantity=10
obj.bags=2

print(obj.quantity+len(obj.__dict__))

10. What will be the output of the following Python code?

class A:
    def __init__(self,x=3):
        self._x = x        
class B(A):
    def __init__(self):
        super().__init__(5)
    def display(self):
        print(self._x)
def main():
    obj = B()
    obj.display()

main()

 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.