There are many different operators that are available to be used within Python. The task at hand will determine which operator will be used.

Arithmetic Operators

In order to do math in Python, these operator symbols can be used to tell Python what type of mathematical operation you would like to conduct.

Operator Operation Example
+ Addition a + b = result
Subtraction a – b = result
* Multiplication a*b = result
/ Division a / b = result
** Power a**b = result
% Modulus (returns
division remainder)
a % b = result

Conditional/Comparison Operators

The operators below can be used to make conditional/comparison statements in Python.The result will be a Boolean value (true or false).

Operator Operation Example
== Equal to a == b
!= Not equal to a != b
> Greater than a > b
< Less than a < b
>= Greater than or equal to a >= b
<= Less than or equal to a <= b

Assignment Operators

The operators below can be used in the assignment statement.

Operator Operation Example
= Assigns Python object to values on
right side of operator
a = b
+= Adds Python object value of itself to
another value, and assigns results
to Python object on left of operator
a += b
-= Subtracts Python object value of itself to
another value, and assigns results
to Python object on left of operator
a -= b
*= Multiplies Python object value of itself to
another value, and assigns results
to Python object on left of operator
a *= b
/= Multiplies Python object value of itself to
another value, and assigns results
to Python object on left of operator
a /= b
**= Performs exponential power of Python object value to
the power of another value, and assigns results
to Python object on left of operator
a **= b

Logical Operators

The operators below can be used in the logical statements.

Operator Operation
and Tests if a and b
or Tests if a or b
not Tests if not a

Identity Operators

The operators below can be used to test the identity of a value. The result will be a Boolean value (true or false).

Operator Operation Example
is Tests if object is the same
as another object
a is b
is not Tests if object is not the same
as another object
a is not b

Membership Operators

The operators below can be used to test the membership of a value, i.e. is value in string, list, or tuple. The result will be a Boolean value (true or false).

Operator Operation Example
in Tests if variable is in sequence or Python object a in b
not in Tests if variable is not in sequence or Python object a not in b

Operator Precedence Rules

Just like when conducting math with pen and paper, there is an order of operations. For conducting math in Python, it’s no different. From highest precedence to lowest precedence, here is the order list:

  • Parenthesis
  • Exponentiation (raising a number to a power)
  • Multiplication, Division, and Remainder
  • Addition and Subtraction
  • Left to Right