题目
题目
单项选择题

Question at position 20 Consider the following class definition: class MyClass: def __init__(self, value): self.value = value def show_value(): print(self.value) What is likely to happen when calling MyClass(10).show_value()? It prints 10. It calls the method without error and returns None.TypeError raised because self is missing in show_value() method definition.It prints self.value as a string.Clear my selection

选项
A.It prints 10.
B.It calls the method without error and returns None.
C.TypeError raised because self is missing in show_value() method definition.
D.It prints self.value as a string.
查看解析

查看解析

标准答案
Please login to view
思路分析
Consider the given class definition and the call sequence. The method show_value is declared as def show_value(): with no parameters. When accessed as an instance method, Python automatically passes the instance as the first argument (self) to the function. Because show_value is define......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

类似问题

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!