Skip to content

Instantly share code, notes, and snippets.

@odubno
Created August 3, 2014 20:14
Show Gist options
  • Save odubno/1a44c5c4c84a6dab1400 to your computer and use it in GitHub Desktop.
Save odubno/1a44c5c4c84a6dab1400 to your computer and use it in GitHub Desktop.
Decorators LESSON 5 - FUNCTIONSASSIGNMENT 1
#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