Skip to content

Magic methods

RauliL edited this page Oct 5, 2014 · 1 revision

Conversion methods

Method Description
_bool_ Boolean representation of object.
_str_ String representation of object.

Arithmetic operators

Method Operator
_add_ +
_sub_ -
_mul_ *
_div_ /
_mod_ %
_and_ &
_or_ |
_xor_ ^
_lsh_ <<
_rsh_ >>
_cmp_ <=>
_eq_ ==
_lt_ <
_gt_ >
_lte_ <=
_gte_ >=
_pos_ Unary +
_neg_ Unary -
_invert_ ~
_inc_ ++
_dec_ --

Operator != is just negated version of ==, e.g. !(foo == bar).

Subscript operators

Method Example
_getitem_ foo[...]
_setitem_ foo[...] = ...

Maybe these should be just __get__ and __set__?

Clone this wiki locally