Python doesn't have private members, so that doesn't help you as much.
>>> def a(u, v):
... def b():
... return u + v
... return b
...
>>> b = a(1,2)
>>> b()
3
Like this, there is no way to access u & v from b. >>> def f():
... x = 5
... class Blub:
... def incx(self):
... x += 1
... def getx(self):
... return x
... return Blub()
...
>>> j = f()
>>> j.incx()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in incx
UnboundLocalError: local variable 'x' referenced before assignment def f():
x = 5
class Blub:
def incx(self):
nonlocal x
x += 1
def getx(self):
return x
return Blub()
j = f()
j.incx()
print(j.getx())
This will print 6, as expected.Leading single underscore is private by convention. Still should generally be avoided, but it’s the proper use.