Python Mathematical Symbols- Complete Reference Guide
What This Guide Covers
You'll find every Python mathematical symbol explained here — operators, bitwise tricks, special functions, and the precedence rules that determine how expressions actually get evaluated. No filler. Just the symbols you need to write real code.
Basic Arithmetic Operators
These are the symbols you use every day for math in Python. Nothing fancy, but you need them memorized.
| Symbol | Operation | Example | Result |
|---|---|---|---|
| + | Addition | 5 + 3 | 8 |
| - | Subtraction | 10 - 4 | 6 |
| * | Multiplication | 6 * 7 | 42 |
| / | Division | 15 / 4 | 3.75 |
| // | Floor Division | 15 // 4 | 3 |
| % | Modulus (remainder) | 15 % 4 | 3 |
| ** | Exponentiation | 2 ** 5 | 32 |
The // floor division operator trips people up. It doesn't round — it cuts off everything after the decimal point. 15 // 4 gives 3, not 3.75.
The % modulus operator returns the remainder. It's not just for math — it's how you check if a number is even or odd: number % 2 == 0 means even.
Comparison Operators
These return True or False. That's it. No ambiguity, no surprises.
| Symbol | Meaning | Example |
|---|---|---|
| == | Equal to | 5 == 5 → True |
| != | Not equal to | 5 != 3 → True |
| > | Greater than | 7 > 5 → True |
| < | Less than | 3 < 8 → True |
| >= | Greater than or equal | 5 >= 5 → True |
| <= | Less than or equal | 4 <= 9 → True |
Common mistake: using = when you mean ==. The single equals assigns. The double equals compares. Mixing them up will silently break your code or throw an error, depending on context.
Logical Operators
These combine boolean values. Python gives you three: and, or, not.
- and — both conditions must be True
- or — at least one condition must be True
- not — inverts the boolean value
Short-circuit evaluation applies here. With and, if the first value is False, Python skips the second check entirely. With or, if the first value is True, the second check gets skipped. This matters when your second check would cause an error.
Example that won't crash: x > 0 and 10 / x > 1. If x is 0, the first condition fails and division never happens.
Bitwise Operators
These operate on individual bits. You won't use them daily, but when you need them, you really need them — flag manipulation, color processing, low-level optimization.
| Symbol | Operation | Example (4 & 8) |
|---|---|---|
| & | Bitwise AND | 4 & 8 → 0 |
| | | Bitwise OR | 4 | 8 → 12 |
| ^ | Bitwise XOR | 4 ^ 8 → 12 |
| ~ | Bitwise NOT | ~4 → -5 |
| << | Left shift | 4 << 1 → 8 |
| >> | Right shift | 4 >> 1 → 2 |
The ~ operator returns the bitwise complement. In practice, ~x equals -(x+1). That's worth memorizing if you're working with binary data.
Assignment Operators
These combine an operation with assignment in one step. Cleaner code, same result.
- x += 5 — add 5 to x
- x -= 3 — subtract 3 from x
- x *= 2 — multiply x by 2
- x /= 4 — divide x by 4
- x //= 2 — floor divide x by 2
- x %= 7 — x becomes remainder of x divided by 7
- x **= 3 — raise x to the power of 3
- x &= 0b1010 — bitwise AND assignment
These work exactly like their two-step equivalents. x += 1 is identical to x = x + 1, just less typing.
Identity vs Membership Operators
Two operators that confuse beginners: is and in. They sound similar but do completely different things.
Identity: is / is not
Checks if two variables point to the same object in memory. Not the same value — the same object.
a = [1, 2, 3] b = [1, 2, 3] c = a a == b # True — same values a is b # False — different objects a is c # True — same object
Membership: in / not in
Checks if a value exists inside a collection (list, tuple, string, dictionary).
"cat" in ["dog", "cat", "bird"] # True "x" in "example" # True 4 in range(10) # True
For dictionaries, in checks keys, not values. "name" in {"name": "John", "age": 30} returns True. "John" in {"name": "John", "age": 30} returns False.
Math Module Constants and Functions
Python's built-in math module gives you constants and functions that go beyond basic operators.
Constants
- math.pi — 3.141592653589793
- math.e — 2.718281828459045
- math.tau — 2π (6.283185307179586)
- math.inf — positive infinity
Common Functions
- math.sqrt(x) — square root
- math.pow(x, y) — x raised to power y
- math.floor(x) — rounds down
- math.ceil(x) — rounds up
- math.trunc(x) — truncates decimal (like floor for positive, ceil for negative)
- math.fabs(x) — absolute value as float
- math.gcd(a, b) — greatest common divisor
- math.log(x, base) — logarithm (defaults to e)
- math.sin(x), math.cos(x), math.tan(x) — trigonometric functions (radians)
Operator Precedence
When you stack operators, Python follows a specific order. Here's the hierarchy from highest to lowest priority:
| Priority | Operators |
|---|---|
| 1 (highest) | ** (exponentiation) |
| 2 | +x, -x, ~x (unary) |
| 3 | *, /, //, % |
| 4 | +, - |
| 5 | <<, >> |
| 6 | & |
| 7 | ^ |
| 8 | | |
| 9 | ==, !=, >, <, >=, <=, is, is not, in, not in |
| 10 | not |
| 11 (lowest) | and |
| 12 | or |
Left-to-right applies within the same priority level, except exponentiation which goes right-to-left. So 2 ** 3 ** 2 equals 2 ** 9 = 512, not 8 ** 2 = 64.
When in doubt, use parentheses. (a + b) * c is clearer than relying on precedence rules.
Getting Started: Practical Examples
Copy these patterns directly into your code.
Check if a number is even or odd
number = 42
if number % 2 == 0:
print("even")
else:
print("odd")
Swap two variables without a temp variable
a, b = 5, 10 a, b = b, a # a is now 10, b is now 5
Calculate percentage change
old_value = 80
new_value = 100
change = (new_value - old_value) / old_value * 100
print(f"{change:.1f}%") # 25.0%
Round to specific decimal places
value = 3.14159 rounded = round(value, 2) # 3.14
Check if value is within a range
x = 5
if 0 < x < 10:
print("within range") # this runs
Yes, Python lets you chain comparisons like that. It reads as 0 < x and x < 10 but cleaner.
Integer division to get weeks from days
total_days = 25
weeks = total_days // 7
remaining_days = total_days % 7
print(f"{weeks} weeks and {remaining_days} days") # 3 weeks and 4 days
Common Mistakes to Avoid
- == vs = — Assignment vs comparison. This is the most frequent bug in conditional statements.
- / vs // — Regular division always returns float. Floor division returns int.
- is vs == — Don't use is for value comparison. It checks object identity, not equality.
- Floating point precision — 0.1 + 0.2 equals 0.30000000000000004. Use math.isclose() for comparisons.
- Operator precedence — 2 + 3 * 4 equals 14, not 20. The multiplication happens first.
- Division by zero — Both / and // crash on zero divisor. % also crashes.
Quick Reference Table
| Category | Symbols |
|---|---|
| Arithmetic | +, -, *, /, //, %, ** |
| Comparison | ==, !=, >, <, >=, <= |
| Logical | and, or, not |
| Bitwise | &, |, ^, ~, <<, >> |
| Assignment | =, +=, -=, *=, /=, //=, %=, **=, &=, |=, ^= |
| Identity | is, is not |
| Membership | in, not in |
Bookmark this page. You'll come back for the precedence table and the floor division gotcha.