Created
October 23, 2013 13:37
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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