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

Questions 11-15 of 100

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

Question 11

MCQ · Single Correct 1 mark
PYTHON
What is the output of the following Python code?
class A:
    def __init__{self}:
        self.v = 1
    def change(self):
        self.v += 1

a = A()
a.change()
getattr(a, 'change')()
print(a.v)

Answers for question 11

Question 12

NAT · Numerical Answer 1 mark
PYTHON
What will be the output of print(hasattr(A(), 'x')) for:
class A:
    def __init__{self}:
        self.x = 10
    def clear(self):
        del self.x

a = A()
a.clear()
print(1 if hasattr(a, 'x') else 0)

Answers for question 12

Question 13

MCQ · Single Correct 1 mark

Which built-in function returns a dictionary containing the instance attributes of an object?

Answers for question 13

Question 14

NAT · Numerical Answer 1 mark
PYTHON
Consider the following snippet:
class Test:
    pass

t = Test()
t.a = 5
t.b = 10
setattr(t, 'c', 15)
print(sum(t.__dict__.values()))

Answers for question 14

Question 15

MCQ · Single Correct 1 mark
PYTHON
What is the output of the following Python code?
class Student:
    def __init__{self, name, marks}:
        self.name = name
        self.marks = marks
    def __str__{self}:
        return f'{self.name}:{self.marks}'

s = Student('Bob', 90)
print(str(s))

Answers for question 15
Scroll to Top