class.py
来自「python的典型方法,对初学的python的人有一定的借鉴作用。」· Python 代码 · 共 49 行
PY
49 行
from time import time
class vector2d(object):
'''2D vectors'''
def __init__(self, x, y):
self.x = x
self.y = y
self.ctime = time()
def __add__(self, other):
return vector2d(self.x+other.x, self.y+other.y)
def __iadd__(self, other):
self.x += other.x
self.y += other.y
return self
def __str__(self):
return "(%d, %d)" % (self.x, self.y)
__repr__ = __str__
def __sub__(self, other):
return vector2d(self.x-other.x, self.y-other.y)
def mult(self, other):
return self.x*other.y - other.x * self.y
class seqIter(object):
def __init__(self, n, m):
self.max = m
self.num = n
def next(self):
if (self.num >= self.max):
raise StopIteration
self.num += 1
return self.num
class seq(object):
def __init__(self, st, ed):
self.start = st
self.end = ed
def __iter__(self):
return seqIter(self.start, self.end)
for x in seq(3, 10):
print x
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?