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

Questions 21-25 of 100

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

Question 21

MCQ · Single Correct 1 mark

In Python, what is a primary use case of @staticmethod?

Answers for question 21

Question 22

NAT · Numerical Answer 1 mark
PYTHON
What is the value printed?
class Tracker:
    data = []
    def add(self, val):
        self.data.append(val)

t1 = Tracker()
t2 = Tracker()
t1.add(10)
t2.add(20)
print(len(Tracker.data))

Answers for question 22

Question 23

MCQ · Single Correct 1 mark

What occurs if a class definition contains multiple __init__ methods?

Answers for question 23

Question 24

NAT · Numerical Answer 1 mark
PYTHON
Evaluate the output:
class Foo:
    def __init__{self, a}:
        self.a = a
    def __add__{self, other}:
        return Foo(self.a + other.a)

f1 = Foo(10)
f2 = Foo(20)
f3 = f1 + f2
print(f3.a)

Answers for question 24

Question 25

MCQ · Single Correct 1 mark
PYTHON
What is the output of the following Python code?
class A:
    pass

a = A()
a.x = 5
delattr(A, 'x') if hasattr(A, 'x') else None
print(a.x)

Answers for question 25
Scroll to Top