Book Image

Mastering Object-oriented Python

By : Steven F. Lott, Steven F. Lott
Book Image

Mastering Object-oriented Python

By: Steven F. Lott, Steven F. Lott

Overview of this book

Table of Contents (26 chapters)
Mastering Object-oriented Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Some Preliminaries
Index

Implementing other special methods


In addition to the core arithmetic and comparison operators, we have a group of additional operators that (generally) we only define for the numbers.Integral values. Since we're not defining integral values, we can avoid these special methods:

Method

Operator

object.__lshift__(self, other)

<<

object.__rshift__(self, other)

>>

object.__and__(self, other)

&

object.__xor__(self, other)

^

object.__or__(self, other)

|

Also, there are reflected versions of these operators:

Method

Operator

object.__rlshift__(self, other)

<<

object.__rrshift__(self, other)

>>

object.__rand__(self, other)

&

object.__rxor__(self, other)

^

object.__ror__(self, other)

|

Additionally, there's a unary operator for a bit-wise inverse of the value:

Method

Operator

object.__invert__(self)

~

Interestingly, some of these operators are defined for the set collection, as well as integral numbers...