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.

MethodSyntaxDescription
+ / - / * / /a + b , a / bAdd, subtract, multiply, and floating-point division.
//a // bFloor Division. Divides two numbers and rounds down the result to the nearest integer.
%a % bModulo. Returns the remainder of division.
**a ** bExponentiation. Raises variable a to the power of b.
+= / -= / *=a += 5In-place math and assignment updates.

Comparison, Logical & Identity

Evaluation operators comparing value equality and memory references.

MethodSyntaxDescription
== / !=a == bCompares if values are equal (==) or not equal (!=).
< / > / <= / >=a >= bMagnitude comparison checks.
and / or / notcond1 and cond2Boolean logical operators checking compound expressions.
is / is nota is bIdentity check. Checks if variables point to the same object address in memory.
in / not initem in containerMembership 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.