Exam PCAP All QuestionsBrowse all questions from this exam
Question 70

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?

    Correct Answer: B

    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.

Discussion
AvidulamOption: B

print(self.get()), B is the answer

wacha1978Option: B

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

guillepowermetalOption: B

correct answer is B

macxszOption: B

assuming indentation is correct: B. print (self.get())

NorasitOption: B

IndentationError

rocky48Option: B

print(self.get()), B is the answer

themeisterOption: B

B is the answer

Shini1Option: B

correct answer is B

FR99Option: B

The correct answer is 'B'

Het_is_je_boy

Should give a Error. Class is not with a capital letter + it has 3 _ should be 2 + wrong indentation.