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

Questions 1-5 of 100

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

Question 1

MCQ · Single Correct 1 mark

Consider the following Python class definition:
class Test:
x = 10
def __init__{self, x}:
self.$x = x

t1 = Test(20)
t2 = Test(30)
print(Test.x, t1.x, t2.x)$

Answers for question 1

Question 2

MCQ · Single Correct 1 mark
PYTHON
What is the output of the following Python program?
class A:
 count = 0
 def __init__{self}:
 A.count += 1

a1 = A()
a2 = A()
a3 = A()
a1.count = 100
print(A.count, a1.count, a2.count)

Answers for question 2

Question 3

NAT · Numerical Answer 1 mark
PYTHON
Consider the following Python code:
class Counter:
 def __init__{self, val=0}:
 self.val = val
 def increment(self, step=1):
 self.val += step
 return self.val

$c = Counter(5)
c.increment()
c.increment(4)
print(c.val)$

Answers for question 3

Question 4

MCQ · Single Correct 1 mark

Which of the following statements about 'self' in Python class methods is CORRECT?

Answers for question 4

Question 5

MCQ · Single Correct 1 mark
Previous Year Question GATE DA 2024 Adapted PYQ
PYTHON
What is the output of the following Python code?
class Sample:
 def __init__{self, lst=[]}:
 self.lst = lst
 def add(self, item):
 self.lst.append(item)

s1 = Sample()
s1.add(1)
s2 = Sample()
s2.add(2)
print(s1.lst)

Answers for question 5
Scroll to Top