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

Questions 51-55 of 100

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

Question 51

MCQ · Single Correct 1 mark

In Python, how is private attribute name mangling implemented for an attribute defined as self.__secret inside class Foo?

Answers for question 51

Question 52

NAT · Numerical Answer 1 mark
PYTHON
What is the output of the following code?
class Secret:
 def __init__{self}:
 self.__val = 42
 def get_val(self):
 return self.__val

s = Secret()
print(getattr(s, '_Secret__val'))

Answers for question 52

Question 53

MCQ · Single Correct 1 mark

What happens when attempting to access s.__val directly from outside class Secret where self.__val = 42?

Answers for question 53

Question 54

NAT · Numerical Answer 1 mark
PYTHON
Consider the code:
class Vector:
 def __init__{self, x, y}:
 self.x = x
 self.y = y
 def __len__{self}:
 return int((self.x**2 + self.y**2)**0.5)

$v = Vector(3, 4)
print(len(v))$

Answers for question 54

Question 55

MCQ · Single Correct 1 mark

Which dunder method must be implemented to make an instance callable like a function (e.g. obj())?

Answers for question 55
Scroll to Top