Skip to content

Instantly share code, notes, and snippets.

@KushalP
Created October 23, 2013 13:37
Show Gist options
  • Save KushalP/7118923 to your computer and use it in GitHub Desktop.
Save KushalP/7118923 to your computer and use it in GitHub Desktop.
A real drawn out example (it's bad) to show how private methods in Python work
class Multiply(object):
def __init__(self, x, y):
self.x, self.y = x, y
def value(self):
return self.__multiply(self.x, self.y)
def __multiply(self, x, y):
return x * y
if __name__ == "__main__":
m = Multiply(2, 4)
print m.value()
print m.__multiply(2, 4) # Will raise an exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment