⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.py

📁 python的典型方法,对初学的python的人有一定的借鉴作用。
💻 PY
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -