Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created October 18, 2011 13:42
Show Gist options
  • Select an option

  • Save pasberth/1295450 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/1295450 to your computer and use it in GitHub Desktop.
(3, 2, 1) + (4, 3, 2) = (7, 5, 3) になるような Point クラス
# -*- 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