PCAP Exam QuestionsBrowse all questions from this exam

PCAP 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?

Show Answer
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

10 comments
Sign in to comment
AvidulamOption: B
Mar 12, 2020

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

wacha1978Option: B
Oct 17, 2021

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
Jun 11, 2020

correct answer is B

macxszOption: B
May 3, 2022

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

Het_is_je_boy
Aug 22, 2020

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

FR99Option: B
Oct 20, 2020

The correct answer is 'B'

Shini1Option: B
Apr 20, 2021

correct answer is B

themeisterOption: B
May 12, 2021

B is the answer

rocky48Option: B
Apr 22, 2022

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

NorasitOption: B
Apr 25, 2022

IndentationError