Could i request an explanation of what this functions purpose is?
def __contains__(self, n):
return n in self.vertDict
__contains__定义类的实例在in或not in运算符(例如,x in foo或x not in foo)的右侧时的行为。[1]
考虑以下示例:
^{pr2}$
Two birds one stone, I sort of understand the 'addEdge' function but what are the arguments h and t? Is it creating edges?
h和{}似乎都是顶点。此方法似乎是在h和{}之间添加一条边,因此它看起来像(h)-(t)。在
# from the name, the method looks like it might be creating edges,
# but let's investigate further!
def addEdge(self,h,t):
# the first "give-away" is it's checking if
# `h` is in `self.vertDict`
if h not in self.vertDict:
# if it *isn't* in `self.vertDict`, it adds it
newV = self.addVert(h)
# it does a similar check for `t`
if t not in self.vertDict:
newV = self.addVert(t)
# it then adds a link, or edge between `h` and `t` here
self.vertDict[h].addnewLink(self.vertDict[t])
__contains__
定义类的实例在in
或not in
运算符(例如,x in foo
或x not in foo
)的右侧时的行为。[1]考虑以下示例:
^{pr2}$h
和{h
和{(h)-(t)
。在资料来源:
[1]What does __contains__ do, what can call __contains__ function
相关问题 更多 >
编程相关推荐