4 ms·
you could also use a generator function - def foo(num=[0]): num[0] = num[0] + 1 return num[0]
by mjhea0 13y ago
you could also use a generator function -
def foo(num=[0]):
num[0] = num[0] + 1
return num[0]
- tome 13y agoHuh? How's that a generator function?
- wahnfrieden 13y agoIt's not a generator, but his intention is clear - mutable keyword arguments allow for some clever tricks.
- deleted 13y ago[deleted]
- jzwinck 13y agoThey sure do--that's why we shouldn't have them. Instead: class Foo: def __init__(self): self.n = 0 def __call__(self): self.n += 1 return self.n foo = Foo()