Python Operators

Mathematical Operators

Operator Description Example
+ Addition 3 + 2 → 5
- Subtraction 3 - 2 → 1
* Multiplication 3 * 2 → 6
/ Division 3 / 2 → 1.5
// Floor Division 3 // 2 → 1
% Modulus (Remainder) 3 % 2 → 1
** Exponentiation
(Power and Root)
3 ** 2 → 9

Comparison Operators

Operator Description Example
== Equal to 2 == 2 → true
!= Not equal to 2 != 3 → true
< Less than 2 < 3 → true
> Greater than 2 > 3 → false
<= Less than or equal to 2 <= 3 → true
>= Greater than or equal to 2 >= 3 → false

Boolean Operators

Operator Description
and True if both operands are true; otherwise false.
or True if at least one operand is true; otherwise false.
not True if the operand is false; otherwise false.

Bitwise Operators

Operator Description
x << n Shift bits of x left by n positions
x >> n Shift bits of x right by n positions
x & y Bitwise AND of x and y
x | y Bitwise OR of x and y
x ^ y Bitwise XOR of x and y
~x Bitwise NOT of x

 

 
 

Please feel free to point out any errors or typos, or share suggestions to improve these notes. English isn't my first language, so if you notice any mistakes, let me know, and I'll be sure to fix them.

FacebookTwitterLinkedinLinkedin
knowledge base

Python

  1. The Python Language
  2. How to Install Python on Your PC
  3. How to Write a Program in Python
  4. How to Use Python in Interactive Mode
  5. Variables
  6. Numbers
  7. Logical Operators
  8. Iterative Structures (or Loops)
  9. Conditional Structures
  10. Exceptions
  11. Files in Python
  12. Classes
  13. Modules

Miscellaneous

Source