7.5 实现其他的特殊方法
有关重要的算术和比较运算符,还包括一组加法运算符,只有numbers.Integral类型的值会用到。由于我们不会去定义整数,因此可以暂时跳过这些特殊方法。
方法 | 运算符 |
|---|---|
object. lshift (self, other) | << |
object. rshift (self, other) | >> |
object. and (self, other) | & |
object. xor (self, other) | ^ |
object. or (self, other) | | |
当然也包括与这些运算符相关的反向版本。
方法 | 运算符 |
|---|---|
object. rlshift (self, other) | << |
object. rrshift (self, other) | >> |
object. rand (self, other) | & |
object. rxor (self, other) | ^ |
object. ror (self, other) | | |
补充一点,还有一个有关位运算值的取反操作。
方法 | 运算符 |
|---|---|
object. invert (self) | << |
有趣的是,这些运算符中的一些被用在了集合和整数中,并没有在有理数中使用它们。定义这些运算符的原则与其他算术运算符是一样的。
