The following class definition is given. We want the show () method to invoke the get () method, and then output the value the get () method returns. Which of the invocations should be used instead of XXX?
The following class definition is given. We want the show () method to invoke the get () method, and then output the value the get () method returns. Which of the invocations should be used instead of XXX?
In Python, to call a method of a class from within another method of the same class, you need to reference it through 'self'. The 'get()' method is a function belonging to the instance, and can be accessed using 'self.get()'. Therefore, to print the return value of 'get()', the correct invocation would be 'print(self.get())'. Thus, the correct answer is option B.
print(self.get()), B is the answer
class C: def __init__(self, val): self.val = val def get(self): return self.val def show(self): print(self.get()) a = C(7) a.show() 7
correct answer is B
assuming indentation is correct: B. print (self.get())
IndentationError
print(self.get()), B is the answer
B is the answer
correct answer is B
The correct answer is 'B'
Should give a Error. Class is not with a capital letter + it has 3 _ should be 2 + wrong indentation.