import PrintHelper
PrintHelper.PrintSubtitle('The idea behind operator overloading')
PrintHelper.PrintSubtitle('Comparisons,比较方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__eq__()','==')
PrintHelper.PrintSampleWithDescription('__ne__()','!=')
PrintHelper.PrintSampleWithDescription('__gt__()','>')
PrintHelper.PrintSampleWithDescription('__ge__()','>=')
PrintHelper.PrintSampleWithDescription('__lt__()','<')
PrintHelper.PrintSampleWithDescription('__le__()','<=')
PrintHelper.PrintHint('__eq__(),==')
PrintHelper.PrintCode('class Point:')
PrintHelper.PrintCode('    def __init__(self,x=0.0,y=0.0):')
PrintHelper.PrintCode('        self.x=x')
PrintHelper.PrintCode('        self.y=y')
PrintHelper.PrintCode('    def __repr__(self):')
PrintHelper.PrintCode('        return \"x:{},y:{}\".format(self.x,self.y)')
class Point:
    def __init__(self,x=0.0,y=0.0):
        self.x=x
        self.y=y
    def __repr__(self):
        return "x:{},y:{}".format(self.x,self.y)
PrintHelper.PrintCode('p1=Point(3,4)')
p1=Point(3,4)
PrintHelper.PrintCode('p2=Point(3,4)')
p2=Point(3,4)
PrintHelper.PrintCode('p3=Point(1,2)')
p3=Point(1,2)
PrintHelper.PrintCode('print(p1 is p2)')
print(p1 is p2)
PrintHelper.PrintCode('print(p1 is p3)')
print(p1 is p3)
PrintHelper.PrintCode('print(p1 == p2)')
print(p1 == p2)
PrintHelper.PrintCode('print(p1 == p3)')
print(p1 == p3)
print('在默认情况下,对象的==和is判断相似')
print('当然,你可以重写它,下面是一则例子')
PrintHelper.PrintCode('class Point:')
PrintHelper.PrintCode('    def __init__(self,x=0.0,y=0.0):')
PrintHelper.PrintCode('        self.x=x')
PrintHelper.PrintCode('        self.y=y')
PrintHelper.PrintCode('    def __repr__(self):')
PrintHelper.PrintCode('        return \"x:{},y:{}\".format(self.x,self.y)')
PrintHelper.PrintCode('    def __eq__(self,p):')
PrintHelper.PrintCode('        return self.x==p.x and self.y==p.y')
class Point:
    def __init__(self,x=0.0,y=0.0):
        self.x=x
        self.y=y
    def __repr__(self):
        return "x:{},y:{}".format(self.x,self.y)
    def __eq__(self,p):
        return self.x==p.x and self.y==p.y
PrintHelper.PrintCode('p1=Point(3,4)')
p1=Point(3,4)
PrintHelper.PrintCode('p2=Point(3,4)')
p2=Point(3,4)
PrintHelper.PrintCode('p3=Point(1,2)')
p3=Point(1,2)
PrintHelper.PrintCode('print(p1 is p2)')
print(p1 is p2)
PrintHelper.PrintCode('print(p1 is p3)')
print(p1 is p3)
PrintHelper.PrintCode('print(p1 == p2)')
print(p1 == p2)
PrintHelper.PrintCode('print(p1 == p3)')
print(p1 == p3)
PrintHelper.PrintSubtitle('Calculations,计算方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__add__()','+,addition')
PrintHelper.PrintSampleWithDescription('__sub__()','-,substraction')
PrintHelper.PrintSampleWithDescription('__mul__()','*,multiplication')
PrintHelper.PrintSampleWithDescription('__truediv__()','/,devision')
PrintHelper.PrintSampleWithDescription('__floordiv__()','//,integer division')
PrintHelper.PrintSampleWithDescription('__mod__()','%,modulo')
PrintHelper.PrintSampleWithDescription('__pow__()','**,power')
PrintHelper.PrintSampleWithDescription('__lshift__()','<<,left shift')
PrintHelper.PrintSampleWithDescription('__rshift__()','>>,right shift')
PrintHelper.PrintSampleWithDescription('__and__()','and,&')
PrintHelper.PrintSampleWithDescription('__or__()','or,|')
PrintHelper.PrintSampleWithDescription('__xor__()','xor,^')
PrintHelper.PrintSubtitle('Unary oprators,一元操作符')
print('一元操作符只对自身起作用')
print('并不是与其他')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__neg__()','-,负状态')
PrintHelper.PrintSampleWithDescription('__pos__()','+,正状态')
PrintHelper.PrintSampleWithDescription('__invert__()','~,按位反置')
PrintHelper.PrintSampleWithDescription('__abs__()','asb(),求绝对值')
PrintHelper.PrintSampleWithDescription('__int__()','int(),求整数')
PrintHelper.PrintSampleWithDescription('__float__()','float(),求浮点数')
PrintHelper.PrintSampleWithDescription('__round__()','round(),求整,返回整数或浮点数,可以提供而外的可选参数来确定精度')
PrintHelper.PrintSampleWithDescription('__bytes__()','类似__str__(),输出BinaryString的表现形式内容')
PrintHelper.PrintSubtitle('Sequences,序列方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__len__()','len(@items),求长度')
PrintHelper.PrintSampleWithDescription('__getitem__()','@items[@key or @index],返回对应键或索引的元素项')
PrintHelper.PrintSampleWithDescription('__setitem__()','@items[@key or @index],对键或索引对应的元素项赋值')
PrintHelper.PrintSampleWithDescription('__delitem__()','del(@items[@key or @index]),删除')
PrintHelper.PrintSampleWithDescription('__missing__()','当__getitem__()无对应值时执行')
PrintHelper.PrintSampleWithDescription('__contains__()','根据输入项判断是否在元素集合中存在,返回True或False')
print('class Mesostic:')
print('    def __init__( self, name, words ):')
print('        self.name, self.words = name, words ')
print('    def __len__( self ):')
print('        return len( self.words )')
print('    def __getitem__( self, n ):')
print('        return self.words[n]')
print('    def __setitem__( self, n, value ):')
print('        self.words[n] = value')
print('    def __delitem__( self, n ):')
print('        del self.words[n] ')

a6a4fa61f70179fd12caf95945b74c7934dc62fa
<mask token>


class Point:

    def __init__(self, x=0.0, y=0.0):
        self.x = x
        self.y = y

    def __repr__(self):
        return 'x:{},y:{}'.format(self.x, self.y)


<mask token>


class Point:

    def __init__(self, x=0.0, y=0.0):
        self.x = x
        self.y = y

    def __repr__(self):
        return 'x:{},y:{}'.format(self.x, self.y)

    def __eq__(self, p):
        return self.x == p.x and self.y == p.y


<mask token>

<mask token>
PrintHelper.PrintSubtitle('The idea behind operator overloading')
PrintHelper.PrintSubtitle('Comparisons,比较方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__eq__()', '==')
PrintHelper.PrintSampleWithDescription('__ne__()', '!=')
PrintHelper.PrintSampleWithDescription('__gt__()', '>')
PrintHelper.PrintSampleWithDescription('__ge__()', '>=')
PrintHelper.PrintSampleWithDescription('__lt__()', '<')
PrintHelper.PrintSampleWithDescription('__le__()', '<=')
PrintHelper.PrintHint('__eq__(),==')
PrintHelper.PrintCode('class Point:')
PrintHelper.PrintCode('    def __init__(self,x=0.0,y=0.0):')
PrintHelper.PrintCode('        self.x=x')
PrintHelper.PrintCode('        self.y=y')
PrintHelper.PrintCode('    def __repr__(self):')
PrintHelper.PrintCode('        return "x:{},y:{}".format(self.x,self.y)')


class Point:

    def __init__(self, x=0.0, y=0.0):
        self.x = x
        self.y = y

    def __repr__(self):
        return 'x:{},y:{}'.format(self.x, self.y)


PrintHelper.PrintCode('p1=Point(3,4)')
<mask token>
PrintHelper.PrintCode('p2=Point(3,4)')
<mask token>
PrintHelper.PrintCode('p3=Point(1,2)')
<mask token>
PrintHelper.PrintCode('print(p1 is p2)')
print(p1 is p2)
PrintHelper.PrintCode('print(p1 is p3)')
print(p1 is p3)
PrintHelper.PrintCode('print(p1 == p2)')
print(p1 == p2)
PrintHelper.PrintCode('print(p1 == p3)')
print(p1 == p3)
print('在默认情况下,对象的==和is判断相似')
print('当然,你可以重写它,下面是一则例子')
PrintHelper.PrintCode('class Point:')
PrintHelper.PrintCode('    def __init__(self,x=0.0,y=0.0):')
PrintHelper.PrintCode('        self.x=x')
PrintHelper.PrintCode('        self.y=y')
PrintHelper.PrintCode('    def __repr__(self):')
PrintHelper.PrintCode('        return "x:{},y:{}".format(self.x,self.y)')
PrintHelper.PrintCode('    def __eq__(self,p):')
PrintHelper.PrintCode('        return self.x==p.x and self.y==p.y')


class Point:

    def __init__(self, x=0.0, y=0.0):
        self.x = x
        self.y = y

    def __repr__(self):
        return 'x:{},y:{}'.format(self.x, self.y)

    def __eq__(self, p):
        return self.x == p.x and self.y == p.y


PrintHelper.PrintCode('p1=Point(3,4)')
<mask token>
PrintHelper.PrintCode('p2=Point(3,4)')
<mask token>
PrintHelper.PrintCode('p3=Point(1,2)')
<mask token>
PrintHelper.PrintCode('print(p1 is p2)')
print(p1 is p2)
PrintHelper.PrintCode('print(p1 is p3)')
print(p1 is p3)
PrintHelper.PrintCode('print(p1 == p2)')
print(p1 == p2)
PrintHelper.PrintCode('print(p1 == p3)')
print(p1 == p3)
PrintHelper.PrintSubtitle('Calculations,计算方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__add__()', '+,addition')
PrintHelper.PrintSampleWithDescription('__sub__()', '-,substraction')
PrintHelper.PrintSampleWithDescription('__mul__()', '*,multiplication')
PrintHelper.PrintSampleWithDescription('__truediv__()', '/,devision')
PrintHelper.PrintSampleWithDescription('__floordiv__()', '//,integer division')
PrintHelper.PrintSampleWithDescription('__mod__()', '%,modulo')
PrintHelper.PrintSampleWithDescription('__pow__()', '**,power')
PrintHelper.PrintSampleWithDescription('__lshift__()', '<<,left shift')
PrintHelper.PrintSampleWithDescription('__rshift__()', '>>,right shift')
PrintHelper.PrintSampleWithDescription('__and__()', 'and,&')
PrintHelper.PrintSampleWithDescription('__or__()', 'or,|')
PrintHelper.PrintSampleWithDescription('__xor__()', 'xor,^')
PrintHelper.PrintSubtitle('Unary oprators,一元操作符')
print('一元操作符只对自身起作用')
print('并不是与其他')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__neg__()', '-,负状态')
PrintHelper.PrintSampleWithDescription('__pos__()', '+,正状态')
PrintHelper.PrintSampleWithDescription('__invert__()', '~,按位反置')
PrintHelper.PrintSampleWithDescription('__abs__()', 'asb(),求绝对值')
PrintHelper.PrintSampleWithDescription('__int__()', 'int(),求整数')
PrintHelper.PrintSampleWithDescription('__float__()', 'float(),求浮点数')
PrintHelper.PrintSampleWithDescription('__round__()',
    'round(),求整,返回整数或浮点数,可以提供而外的可选参数来确定精度')
PrintHelper.PrintSampleWithDescription('__bytes__()',
    '类似__str__(),输出BinaryString的表现形式内容')
PrintHelper.PrintSubtitle('Sequences,序列方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__len__()', 'len(@items),求长度')
PrintHelper.PrintSampleWithDescription('__getitem__()',
    '@items[@key or @index],返回对应键或索引的元素项')
PrintHelper.PrintSampleWithDescription('__setitem__()',
    '@items[@key or @index],对键或索引对应的元素项赋值')
PrintHelper.PrintSampleWithDescription('__delitem__()',
    'del(@items[@key or @index]),删除')
PrintHelper.PrintSampleWithDescription('__missing__()', '当__getitem__()无对应值时执行'
    )
PrintHelper.PrintSampleWithDescription('__contains__()',
    '根据输入项判断是否在元素集合中存在,返回True或False')
print('class Mesostic:')
print('    def __init__( self, name, words ):')
print('        self.name, self.words = name, words ')
print('    def __len__( self ):')
print('        return len( self.words )')
print('    def __getitem__( self, n ):')
print('        return self.words[n]')
print('    def __setitem__( self, n, value ):')
print('        self.words[n] = value')
print('    def __delitem__( self, n ):')
print('        del self.words[n] ')

<mask token>
PrintHelper.PrintSubtitle('The idea behind operator overloading')
PrintHelper.PrintSubtitle('Comparisons,比较方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__eq__()', '==')
PrintHelper.PrintSampleWithDescription('__ne__()', '!=')
PrintHelper.PrintSampleWithDescription('__gt__()', '>')
PrintHelper.PrintSampleWithDescription('__ge__()', '>=')
PrintHelper.PrintSampleWithDescription('__lt__()', '<')
PrintHelper.PrintSampleWithDescription('__le__()', '<=')
PrintHelper.PrintHint('__eq__(),==')
PrintHelper.PrintCode('class Point:')
PrintHelper.PrintCode('    def __init__(self,x=0.0,y=0.0):')
PrintHelper.PrintCode('        self.x=x')
PrintHelper.PrintCode('        self.y=y')
PrintHelper.PrintCode('    def __repr__(self):')
PrintHelper.PrintCode('        return "x:{},y:{}".format(self.x,self.y)')


class Point:

    def __init__(self, x=0.0, y=0.0):
        self.x = x
        self.y = y

    def __repr__(self):
        return 'x:{},y:{}'.format(self.x, self.y)


PrintHelper.PrintCode('p1=Point(3,4)')
p1 = Point(3, 4)
PrintHelper.PrintCode('p2=Point(3,4)')
p2 = Point(3, 4)
PrintHelper.PrintCode('p3=Point(1,2)')
p3 = Point(1, 2)
PrintHelper.PrintCode('print(p1 is p2)')
print(p1 is p2)
PrintHelper.PrintCode('print(p1 is p3)')
print(p1 is p3)
PrintHelper.PrintCode('print(p1 == p2)')
print(p1 == p2)
PrintHelper.PrintCode('print(p1 == p3)')
print(p1 == p3)
print('在默认情况下,对象的==和is判断相似')
print('当然,你可以重写它,下面是一则例子')
PrintHelper.PrintCode('class Point:')
PrintHelper.PrintCode('    def __init__(self,x=0.0,y=0.0):')
PrintHelper.PrintCode('        self.x=x')
PrintHelper.PrintCode('        self.y=y')
PrintHelper.PrintCode('    def __repr__(self):')
PrintHelper.PrintCode('        return "x:{},y:{}".format(self.x,self.y)')
PrintHelper.PrintCode('    def __eq__(self,p):')
PrintHelper.PrintCode('        return self.x==p.x and self.y==p.y')


class Point:

    def __init__(self, x=0.0, y=0.0):
        self.x = x
        self.y = y

    def __repr__(self):
        return 'x:{},y:{}'.format(self.x, self.y)

    def __eq__(self, p):
        return self.x == p.x and self.y == p.y


PrintHelper.PrintCode('p1=Point(3,4)')
p1 = Point(3, 4)
PrintHelper.PrintCode('p2=Point(3,4)')
p2 = Point(3, 4)
PrintHelper.PrintCode('p3=Point(1,2)')
p3 = Point(1, 2)
PrintHelper.PrintCode('print(p1 is p2)')
print(p1 is p2)
PrintHelper.PrintCode('print(p1 is p3)')
print(p1 is p3)
PrintHelper.PrintCode('print(p1 == p2)')
print(p1 == p2)
PrintHelper.PrintCode('print(p1 == p3)')
print(p1 == p3)
PrintHelper.PrintSubtitle('Calculations,计算方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__add__()', '+,addition')
PrintHelper.PrintSampleWithDescription('__sub__()', '-,substraction')
PrintHelper.PrintSampleWithDescription('__mul__()', '*,multiplication')
PrintHelper.PrintSampleWithDescription('__truediv__()', '/,devision')
PrintHelper.PrintSampleWithDescription('__floordiv__()', '//,integer division')
PrintHelper.PrintSampleWithDescription('__mod__()', '%,modulo')
PrintHelper.PrintSampleWithDescription('__pow__()', '**,power')
PrintHelper.PrintSampleWithDescription('__lshift__()', '<<,left shift')
PrintHelper.PrintSampleWithDescription('__rshift__()', '>>,right shift')
PrintHelper.PrintSampleWithDescription('__and__()', 'and,&')
PrintHelper.PrintSampleWithDescription('__or__()', 'or,|')
PrintHelper.PrintSampleWithDescription('__xor__()', 'xor,^')
PrintHelper.PrintSubtitle('Unary oprators,一元操作符')
print('一元操作符只对自身起作用')
print('并不是与其他')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__neg__()', '-,负状态')
PrintHelper.PrintSampleWithDescription('__pos__()', '+,正状态')
PrintHelper.PrintSampleWithDescription('__invert__()', '~,按位反置')
PrintHelper.PrintSampleWithDescription('__abs__()', 'asb(),求绝对值')
PrintHelper.PrintSampleWithDescription('__int__()', 'int(),求整数')
PrintHelper.PrintSampleWithDescription('__float__()', 'float(),求浮点数')
PrintHelper.PrintSampleWithDescription('__round__()',
    'round(),求整,返回整数或浮点数,可以提供而外的可选参数来确定精度')
PrintHelper.PrintSampleWithDescription('__bytes__()',
    '类似__str__(),输出BinaryString的表现形式内容')
PrintHelper.PrintSubtitle('Sequences,序列方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__len__()', 'len(@items),求长度')
PrintHelper.PrintSampleWithDescription('__getitem__()',
    '@items[@key or @index],返回对应键或索引的元素项')
PrintHelper.PrintSampleWithDescription('__setitem__()',
    '@items[@key or @index],对键或索引对应的元素项赋值')
PrintHelper.PrintSampleWithDescription('__delitem__()',
    'del(@items[@key or @index]),删除')
PrintHelper.PrintSampleWithDescription('__missing__()', '当__getitem__()无对应值时执行'
    )
PrintHelper.PrintSampleWithDescription('__contains__()',
    '根据输入项判断是否在元素集合中存在,返回True或False')
print('class Mesostic:')
print('    def __init__( self, name, words ):')
print('        self.name, self.words = name, words ')
print('    def __len__( self ):')
print('        return len( self.words )')
print('    def __getitem__( self, n ):')
print('        return self.words[n]')
print('    def __setitem__( self, n, value ):')
print('        self.words[n] = value')
print('    def __delitem__( self, n ):')
print('        del self.words[n] ')

import PrintHelper
PrintHelper.PrintSubtitle('The idea behind operator overloading')
PrintHelper.PrintSubtitle('Comparisons,比较方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__eq__()', '==')
PrintHelper.PrintSampleWithDescription('__ne__()', '!=')
PrintHelper.PrintSampleWithDescription('__gt__()', '>')
PrintHelper.PrintSampleWithDescription('__ge__()', '>=')
PrintHelper.PrintSampleWithDescription('__lt__()', '<')
PrintHelper.PrintSampleWithDescription('__le__()', '<=')
PrintHelper.PrintHint('__eq__(),==')
PrintHelper.PrintCode('class Point:')
PrintHelper.PrintCode('    def __init__(self,x=0.0,y=0.0):')
PrintHelper.PrintCode('        self.x=x')
PrintHelper.PrintCode('        self.y=y')
PrintHelper.PrintCode('    def __repr__(self):')
PrintHelper.PrintCode('        return "x:{},y:{}".format(self.x,self.y)')


class Point:

    def __init__(self, x=0.0, y=0.0):
        self.x = x
        self.y = y

    def __repr__(self):
        return 'x:{},y:{}'.format(self.x, self.y)


PrintHelper.PrintCode('p1=Point(3,4)')
p1 = Point(3, 4)
PrintHelper.PrintCode('p2=Point(3,4)')
p2 = Point(3, 4)
PrintHelper.PrintCode('p3=Point(1,2)')
p3 = Point(1, 2)
PrintHelper.PrintCode('print(p1 is p2)')
print(p1 is p2)
PrintHelper.PrintCode('print(p1 is p3)')
print(p1 is p3)
PrintHelper.PrintCode('print(p1 == p2)')
print(p1 == p2)
PrintHelper.PrintCode('print(p1 == p3)')
print(p1 == p3)
print('在默认情况下,对象的==和is判断相似')
print('当然,你可以重写它,下面是一则例子')
PrintHelper.PrintCode('class Point:')
PrintHelper.PrintCode('    def __init__(self,x=0.0,y=0.0):')
PrintHelper.PrintCode('        self.x=x')
PrintHelper.PrintCode('        self.y=y')
PrintHelper.PrintCode('    def __repr__(self):')
PrintHelper.PrintCode('        return "x:{},y:{}".format(self.x,self.y)')
PrintHelper.PrintCode('    def __eq__(self,p):')
PrintHelper.PrintCode('        return self.x==p.x and self.y==p.y')


class Point:

    def __init__(self, x=0.0, y=0.0):
        self.x = x
        self.y = y

    def __repr__(self):
        return 'x:{},y:{}'.format(self.x, self.y)

    def __eq__(self, p):
        return self.x == p.x and self.y == p.y


PrintHelper.PrintCode('p1=Point(3,4)')
p1 = Point(3, 4)
PrintHelper.PrintCode('p2=Point(3,4)')
p2 = Point(3, 4)
PrintHelper.PrintCode('p3=Point(1,2)')
p3 = Point(1, 2)
PrintHelper.PrintCode('print(p1 is p2)')
print(p1 is p2)
PrintHelper.PrintCode('print(p1 is p3)')
print(p1 is p3)
PrintHelper.PrintCode('print(p1 == p2)')
print(p1 == p2)
PrintHelper.PrintCode('print(p1 == p3)')
print(p1 == p3)
PrintHelper.PrintSubtitle('Calculations,计算方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__add__()', '+,addition')
PrintHelper.PrintSampleWithDescription('__sub__()', '-,substraction')
PrintHelper.PrintSampleWithDescription('__mul__()', '*,multiplication')
PrintHelper.PrintSampleWithDescription('__truediv__()', '/,devision')
PrintHelper.PrintSampleWithDescription('__floordiv__()', '//,integer division')
PrintHelper.PrintSampleWithDescription('__mod__()', '%,modulo')
PrintHelper.PrintSampleWithDescription('__pow__()', '**,power')
PrintHelper.PrintSampleWithDescription('__lshift__()', '<<,left shift')
PrintHelper.PrintSampleWithDescription('__rshift__()', '>>,right shift')
PrintHelper.PrintSampleWithDescription('__and__()', 'and,&')
PrintHelper.PrintSampleWithDescription('__or__()', 'or,|')
PrintHelper.PrintSampleWithDescription('__xor__()', 'xor,^')
PrintHelper.PrintSubtitle('Unary oprators,一元操作符')
print('一元操作符只对自身起作用')
print('并不是与其他')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__neg__()', '-,负状态')
PrintHelper.PrintSampleWithDescription('__pos__()', '+,正状态')
PrintHelper.PrintSampleWithDescription('__invert__()', '~,按位反置')
PrintHelper.PrintSampleWithDescription('__abs__()', 'asb(),求绝对值')
PrintHelper.PrintSampleWithDescription('__int__()', 'int(),求整数')
PrintHelper.PrintSampleWithDescription('__float__()', 'float(),求浮点数')
PrintHelper.PrintSampleWithDescription('__round__()',
    'round(),求整,返回整数或浮点数,可以提供而外的可选参数来确定精度')
PrintHelper.PrintSampleWithDescription('__bytes__()',
    '类似__str__(),输出BinaryString的表现形式内容')
PrintHelper.PrintSubtitle('Sequences,序列方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__len__()', 'len(@items),求长度')
PrintHelper.PrintSampleWithDescription('__getitem__()',
    '@items[@key or @index],返回对应键或索引的元素项')
PrintHelper.PrintSampleWithDescription('__setitem__()',
    '@items[@key or @index],对键或索引对应的元素项赋值')
PrintHelper.PrintSampleWithDescription('__delitem__()',
    'del(@items[@key or @index]),删除')
PrintHelper.PrintSampleWithDescription('__missing__()', '当__getitem__()无对应值时执行'
    )
PrintHelper.PrintSampleWithDescription('__contains__()',
    '根据输入项判断是否在元素集合中存在,返回True或False')
print('class Mesostic:')
print('    def __init__( self, name, words ):')
print('        self.name, self.words = name, words ')
print('    def __len__( self ):')
print('        return len( self.words )')
print('    def __getitem__( self, n ):')
print('        return self.words[n]')
print('    def __setitem__( self, n, value ):')
print('        self.words[n] = value')
print('    def __delitem__( self, n ):')
print('        del self.words[n] ')

import PrintHelper
PrintHelper.PrintSubtitle('The idea behind operator overloading')
PrintHelper.PrintSubtitle('Comparisons,比较方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__eq__()','==')
PrintHelper.PrintSampleWithDescription('__ne__()','!=')
PrintHelper.PrintSampleWithDescription('__gt__()','>')
PrintHelper.PrintSampleWithDescription('__ge__()','>=')
PrintHelper.PrintSampleWithDescription('__lt__()','<')
PrintHelper.PrintSampleWithDescription('__le__()','<=')
PrintHelper.PrintHint('__eq__(),==')
PrintHelper.PrintCode('class Point:')
PrintHelper.PrintCode('    def __init__(self,x=0.0,y=0.0):')
PrintHelper.PrintCode('        self.x=x')
PrintHelper.PrintCode('        self.y=y')
PrintHelper.PrintCode('    def __repr__(self):')
PrintHelper.PrintCode('        return \"x:{},y:{}\".format(self.x,self.y)')
class Point:
    def __init__(self,x=0.0,y=0.0):
        self.x=x
        self.y=y
    def __repr__(self):
        return "x:{},y:{}".format(self.x,self.y)
PrintHelper.PrintCode('p1=Point(3,4)')
p1=Point(3,4)
PrintHelper.PrintCode('p2=Point(3,4)')
p2=Point(3,4)
PrintHelper.PrintCode('p3=Point(1,2)')
p3=Point(1,2)
PrintHelper.PrintCode('print(p1 is p2)')
print(p1 is p2)
PrintHelper.PrintCode('print(p1 is p3)')
print(p1 is p3)
PrintHelper.PrintCode('print(p1 == p2)')
print(p1 == p2)
PrintHelper.PrintCode('print(p1 == p3)')
print(p1 == p3)
print('在默认情况下,对象的==和is判断相似')
print('当然,你可以重写它,下面是一则例子')
PrintHelper.PrintCode('class Point:')
PrintHelper.PrintCode('    def __init__(self,x=0.0,y=0.0):')
PrintHelper.PrintCode('        self.x=x')
PrintHelper.PrintCode('        self.y=y')
PrintHelper.PrintCode('    def __repr__(self):')
PrintHelper.PrintCode('        return \"x:{},y:{}\".format(self.x,self.y)')
PrintHelper.PrintCode('    def __eq__(self,p):')
PrintHelper.PrintCode('        return self.x==p.x and self.y==p.y')
class Point:
    def __init__(self,x=0.0,y=0.0):
        self.x=x
        self.y=y
    def __repr__(self):
        return "x:{},y:{}".format(self.x,self.y)
    def __eq__(self,p):
        return self.x==p.x and self.y==p.y
PrintHelper.PrintCode('p1=Point(3,4)')
p1=Point(3,4)
PrintHelper.PrintCode('p2=Point(3,4)')
p2=Point(3,4)
PrintHelper.PrintCode('p3=Point(1,2)')
p3=Point(1,2)
PrintHelper.PrintCode('print(p1 is p2)')
print(p1 is p2)
PrintHelper.PrintCode('print(p1 is p3)')
print(p1 is p3)
PrintHelper.PrintCode('print(p1 == p2)')
print(p1 == p2)
PrintHelper.PrintCode('print(p1 == p3)')
print(p1 == p3)
PrintHelper.PrintSubtitle('Calculations,计算方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__add__()','+,addition')
PrintHelper.PrintSampleWithDescription('__sub__()','-,substraction')
PrintHelper.PrintSampleWithDescription('__mul__()','*,multiplication')
PrintHelper.PrintSampleWithDescription('__truediv__()','/,devision')
PrintHelper.PrintSampleWithDescription('__floordiv__()','//,integer division')
PrintHelper.PrintSampleWithDescription('__mod__()','%,modulo')
PrintHelper.PrintSampleWithDescription('__pow__()','**,power')
PrintHelper.PrintSampleWithDescription('__lshift__()','<<,left shift')
PrintHelper.PrintSampleWithDescription('__rshift__()','>>,right shift')
PrintHelper.PrintSampleWithDescription('__and__()','and,&')
PrintHelper.PrintSampleWithDescription('__or__()','or,|')
PrintHelper.PrintSampleWithDescription('__xor__()','xor,^')
PrintHelper.PrintSubtitle('Unary oprators,一元操作符')
print('一元操作符只对自身起作用')
print('并不是与其他')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__neg__()','-,负状态')
PrintHelper.PrintSampleWithDescription('__pos__()','+,正状态')
PrintHelper.PrintSampleWithDescription('__invert__()','~,按位反置')
PrintHelper.PrintSampleWithDescription('__abs__()','asb(),求绝对值')
PrintHelper.PrintSampleWithDescription('__int__()','int(),求整数')
PrintHelper.PrintSampleWithDescription('__float__()','float(),求浮点数')
PrintHelper.PrintSampleWithDescription('__round__()','round(),求整,返回整数或浮点数,可以提供而外的可选参数来确定精度')
PrintHelper.PrintSampleWithDescription('__bytes__()','类似__str__(),输出BinaryString的表现形式内容')
PrintHelper.PrintSubtitle('Sequences,序列方法')
PrintHelper.PrintHint('操作符列表')
PrintHelper.PrintSampleWithDescription('__len__()','len(@items),求长度')
PrintHelper.PrintSampleWithDescription('__getitem__()','@items[@key or @index],返回对应键或索引的元素项')
PrintHelper.PrintSampleWithDescription('__setitem__()','@items[@key or @index],对键或索引对应的元素项赋值')
PrintHelper.PrintSampleWithDescription('__delitem__()','del(@items[@key or @index]),删除')
PrintHelper.PrintSampleWithDescription('__missing__()','当__getitem__()无对应值时执行')
PrintHelper.PrintSampleWithDescription('__contains__()','根据输入项判断是否在元素集合中存在,返回True或False')
print('class Mesostic:')
print('    def __init__( self, name, words ):')
print('        self.name, self.words = name, words ')
print('    def __len__( self ):')
print('        return len( self.words )')
print('    def __getitem__( self, n ):')
print('        return self.words[n]')
print('    def __setitem__( self, n, value ):')
print('        self.words[n] = value')
print('    def __delitem__( self, n ):')
print('        del self.words[n] ')
