GATE DA Python OOP, Modules & Exception Handling | Set 1

Questions 16-20 of 100

0% completed (0/100 answered)
Your score 0/100 0 answered
Correct 0 Incorrect 0 Unanswered 100 Accuracy 0%

Question 16

NAT · Numerical Answer 1 mark
PYTHON
What is the output of the following Python code?
class A:
    def __init__{self, x}:
        self.x = x

list_of_objs = [A(i) for i in range(1, 6)]
print(sum(obj.x for obj in list_of_objs))

Answers for question 16

Question 17

MCQ · Single Correct 1 mark

What is the purpose of @classmethod decorator in Python?

Answers for question 17

Question 18

NAT · Numerical Answer 1 mark
PYTHON
What is the output of the following code?
class Math:
    @staticmethod
    def add(a, b):
        return a + b
    @classmethod
    def double_add(cls, a, b):
        return cls.add(a, b) * 2

print(Math.double_add(3, 4))

Answers for question 18

Question 19

MCQ · Single Correct 1 mark
PYTHON
What is the output of the following code?
class Base:
    @classmethod
    def identify(cls):
        return cls.__name__

class Derived(Base):
    pass

print(Derived.identify())

Answers for question 19

Question 20

NAT · Numerical Answer 1 mark
PYTHON
Consider the following Python code:
class Item:
    rate = 1.1
    def __init__{self, price}:
        self.price = price
    def total(self):
        return int(self.price * Item.rate)

i = Item(100)
i.rate = 1.5
print(i.total())

Answers for question 20
Scroll to Top