Created
October 18, 2011 13:42
-
-
Save pasberth/1295450 to your computer and use it in GitHub Desktop.
(3, 2, 1) + (4, 3, 2) = (7, 5, 3) になるような Point クラス
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
| # -*- coding: utf-8 -*- | |
| class Point: | |
| def __init__(self, *vectors): | |
| self.vectors = vectors | |
| def __str__(self): | |
| return str(self.vectors) | |
| def __iter__(self): | |
| return self.vectors.__iter__() | |
| def __sub__(self, point): | |
| return Point(*[v1 - v2 for v1, v2 in zip(self, point)]) | |
| def __add__(self, point): | |
| return Point(*[v1 + v2 for v1, v2 in zip(self, point)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment