Created
August 3, 2014 20:14
-
-
Save odubno/1a44c5c4c84a6dab1400 to your computer and use it in GitHub Desktop.
Decorators LESSON 5 - FUNCTIONSASSIGNMENT 1
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
#I don't understand the need for classes or use of classes. What's __repr__? Why do we have to use the double underscore before the term both for __init__ and __repr__. | |
class coordinate(object): | |
def __init__(self, x, y): | |
self.x = x | |
self.y = y | |
def __repr__(self): | |
return "coord: " + str(self.__dict__) | |
def add(a, b): | |
return coordinate(a.x + b.x, a.y + b.y) | |
def sub(a, b): | |
return coordinate(a.x - b.x, a.y + b.y) | |
one = coordinate(100, 200) | |
two = coordinate(300, 200) | |
print add(one, two) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment