Appendix D: Python operators

This appendix lists the Python operators you are likely to need, organised by category.

D.1. Arithmetic operators

Precedence Operator Name Description

Highest

-x

Unary minus

Negation

High

*

Multiplication

Multiply values

/

True division

Floating-point division

//

Floor division

Integer division (floor)

%

Modulo

Remainder

Normal

+

Addition

Add values

-

Subtraction

Subtract value

D.2. Boolean operators

Precedence Operator Name Description

Highest

not

Logical NOT

Inverts truth value

High

and

Logical AND

True if both operands are true

Normal

or

Logical OR

True if either operand is true

D.3. Comparison operators

Precedence Operator Name Description

Normal

<, <=, >, >=

Ordering

Relational comparisons

==, !=

Equality

Value comparison

is, is not

Identity

Object identity test

in, not in

Membership

Membership test

D.4. More operators

In this appendix we have omitted some advanced operators. There is a full list of operators in the Python documentation.


1. https://shakespeareoxfordfellowship.org/shakespeare-by-the-numbers-what-stylometrics-can-and-cannot-tell-us