Python Operators Cheat Sheet
Master arithmetic, comparison, logical, bitwise, assignment, and identity operators in Python.
Arithmetic, Floor & Assignment
Standard operators representing mathematical calculations and assignment changes.
| Method | Syntax | Description |
|---|---|---|
| + / - / * / / | a + b , a / b | Add, subtract, multiply, and floating-point division. |
| // | a // b | Floor Division. Divides two numbers and rounds down the result to the nearest integer. |
| % | a % b | Modulo. Returns the remainder of division. |
| ** | a ** b | Exponentiation. Raises variable a to the power of b. |
| += / -= / *= | a += 5 | In-place math and assignment updates. |
Comparison, Logical & Identity
Evaluation operators comparing value equality and memory references.
| Method | Syntax | Description |
|---|---|---|
| == / != | a == b | Compares if values are equal (==) or not equal (!=). |
| < / > / <= / >= | a >= b | Magnitude comparison checks. |
| and / or / not | cond1 and cond2 | Boolean logical operators checking compound expressions. |
| is / is not | a is b | Identity check. Checks if variables point to the same object address in memory. |
| in / not in | item in container | Membership check. Evaluates True if item is found in sequence. |
Frequently Asked Questions
What is the difference between / and // operators?
The / operator performs floating-point division, returning a float (e.g., 5 / 2 = 2.5), while // performs floor division, rounding down to the nearest integer (e.g., 5 // 2 = 2).
What is the difference between == and is?
== checks if the values of two objects are equal, whereas is checks if the two variables refer to the exact same object in memory.
Keep Learning
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.