Before looking at the various kinds of numbers available, we'll introduce the Python operators. The operators fall into three broad groups:
Group |
Operators |
---|---|
Arithmetic |
|
Bit-oriented |
|
Comparison |
|
The differences between these groups are partly subjective. There's only a small technical difference in the way the comparison operators work. Most of the operators are binary, only one (~
) is unary, and a few (+
, -
, *
, **
) can be used in either context.
The +
, -
, *
, /
, and %
operators have meanings similar to those used other programming languages. There is an arithmetic meaning for –
and +
. Python adds the **
operator when raising a number to a power. The **
operator takes higher precedence than the unary form -
; this means that -2**4
is -16
.
Bit-oriented operators apply only to integers. They also apply to sets. These are emphatically not logical operators. The actual...