Python 类的深入介绍
1. 基础类检查
1.1 代码示例及问题
以下是一段 Python 代码,我们需要分析其指定行的输出结果:
class MyClass (object):
def method1(self, param_tuple):
self.local_list = []
for element in param_tuple:
if element > 10:
self.local_list.append(element)
def method2(self):
self.sum_int = 0
for element in self.local_list:
self.sum_int += element
return self.sum_int
inst1 = MyClass()
inst2 = MyClass()
inst1.method1([1,2,3])
print(inst1.local_list)
# Line 1
inst1.method1([10,11,12])
print(inst1.local_list)
# Line 2
print(inst1.method2())
# Line 3
# inst2.method2()
# Line 4
问题如下:
- (a) 上述程序的 Line 1 会产生什么输出?
- (b) 上述程序的 Line 2 会
超级会员免费看
订阅专栏 解锁全文
1665

被折叠的 条评论
为什么被折叠?



