【发布时间】:2017-05-30 06:05:14
【问题描述】:
我想从 Python3 中的 self 函数中迭代 self 属性,但我没有找到任何类似的。我发现了如何在课堂之外做到这一点here。
我的问题是,有可能吗?
class Foo:
def __init__(self, attr1, attr2):
self.attr1 = attr1
self.attr2 = attr2
def method1(self):
#Return sum of the values of the self attributes
pass
【问题讨论】:
-
你想遍历
attr1,attr2? -
是的,themiurge 和 Gustavo 在下面评论正确答案。
标签: python python-3.x