operators.py

来自「Boost provides free peer-reviewed portab」· Python 代码 · 共 103 行

PY
103
字号
# Copyright David Abrahams 2004. Distributed under the Boost# Software License, Version 1.0. (See accompanying# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)'''>>> from operators_ext import *  Check __nonzero__ support  >>> assert X(2)>>> assert not X(0) ---- >>> x = X(42)>>> x.value()42>>> y = x - X(5)>>> y.value()37>>> y = x - 4>>> y.value()38>>> y = 3 - x>>> y.value()-39>>> (-y).value()39>>> (x + y).value()3>>> abs(y).value()39>>> x < 100>>> x < 431>>> 10 < x1>>> 43 < x0>>> x < y0>>> y < x1 ------>>> x > 101>>> x > 430>>> 10 > x0>>> 43 > x1>>> x > y1>>> y > x0>>> y = x - 5>>> x -= y>>> x.value()5>>> str(x)'5'>>> z = Z(10)>>> int(z)10>>> float(z)10.0>>> complex(z)(10+0j)>>> pow(2,x)32>>> pow(x,2).value()25>>> pow(X(2),x).value()32'''def run(args = None):    import sys    import doctest    if args is not None:        sys.argv = args    return doctest.testmod(sys.modules.get(__name__))    if __name__ == '__main__':    print "running..."    import sys    status = run()[0]    if (status == 0): print "Done."    sys.exit(status)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?