• Save
  • Run All Cells
  • Clear All Output
  • Runtime
  • Download
  • Difficulty Rating

Loading Runtime

What is an "operator"?

An "operator" is a symbol that does something in Python. It does an "operation".

Typically, an operator has values on the left and right side of it. These values are called "operands". An operand is any value an operator acts on.

For example, if I write the line 2 + 3, the plus sign (addition operator) is the operator, and the numbers (2 and 3) are the operands.

Categories of Operators

There are seven categories of operators in Python. They are:

Arithmetic Operators

Useful for doing math with Python. You might need to use parentheses in conjunction with these arithmetic operators ((, )) if you want to enforce a specific order of operations.

  • Addition Operator: +
  • Subtraction Operator: -
  • Multiplication Operator: *
  • Division Operator: /
  • Floor Division Operator: //
  • Modulus Operator: %
  • Exponentiation Operator: **

Addition Operator

5

Subtraction Operator

3

Multiplication Operator

15

Division Operator

1.3333333333333333

Floor Division Operator

1

Modulus Operator

2

Exponentiation Operator

8

Comparison Operators

Used to compare two values. Each of these operators results in one of two boolean values (true or false).

  • Equality Operator: ==
  • Inequality Operator: !=
  • Greater Than Operator: >
  • Less Than Operator: <
  • Greater Than or Equal To Operator: >=
  • Less Than or Equal To Operator: <=

Equality Operator

false

Inequality Operator

true

Greater Than Operator

true

Less Than Operator

false

Greater Than or Equal To Operator

true

Less Than or Equal To Operator

false

Logical Operators

  • and Operator
  • or Operator
  • not Operator

and Operator

true
false
false

or Operator

true
true
false

not Operator

false
true

Bitwise Operators

Converts integers to their binary representation and then compares each corresponding pair of binary bits using the designated method. The resulting binary number is then translated back into decimal format.

  • Bitwise AND Operator: &
  • Bitwise OR Operator: |
  • Bitwise XOR Operator: ^
  • Bitwise NOT Operator: ~
  • Bitwise Right Shift Operator: >>
  • Bitwise Left Shift Operator: <<

Bitwise AND Operator

3

Bitwise OR Operator

15

Bitwise XOR Operator

11

Bitwise NOT Operator

-8

Bitwise Right Shift Operator

28672

Bitwise Left Shift Operator

0

Assignment Operators

  • Assignment Operator: =
  • Addition Assignment Operator: +=
  • Subtraction Assignment Operator: -=
  • Multiplication Assignment Operator: *=
  • Division Assignment Operator: /=
  • Modulus Assignment Operator: %=
  • Floor Division Assignment Operator: //=
  • Exponentiation Assignment Operator: **=
  • Bitwise AND Assignment Operator: &=
  • Bitwise OR Assignment Operator: |=
  • Bitwise XOR Assignment Operator: ^=
  • Bitwise Right Shift Assignment Operator: >>=
  • Bitwise Left Shift Assignment Operator: <<=
  • Walrus Operator: :=

Assignment Operator

3

Addition Assignment Operator

7

Subtraction Assignment Operator

6

Multiplication Assignment Operator

12

Division Assignment Operator

6

Modulus Assignment Operator

0

Floor Division Assignment Operator

7

Exponentiation Assignment Operator

49

Bitwise AND Assignment Operator

4

Bitwise OR Assignment Operator

12

Bitwise XOR Assignment Operator

7

Bitwise Right Shift Operator

7

Bitwise Left Shift Operator

15360

Walrus Operator

[4, 16, 36, 64, 100]

Identity Operators

Compares the memory locations of two objects.

  • is Operator
  • is not Operator

is Operator

true
false

is not Operator

false
true

Membership Operators:

Tests if a value is found in a sequence (string, list tuple, dictionary, etc.).

  • in Operator
  • not in Operator

in Operator

true
false

not in Operator

false
true