Python's arithmetic operators cover the basics you'd expect — addition, subtraction, multiplication — plus two forms of division: / (true division, always returns a float) and // (floor division, rounds toward negative infinity). % returns the remainder of floor division, and ** raises a number to a power, including fractional and negative exponents. + and * are also overloaded for sequences: concatenation for strings/lists, and repetition when multiplying a sequence by an int.
1Understanding Arithmetic Operators
Python's arithmetic operators cover the basics you'd expect — addition, subtraction, multiplication — plus two forms of division: / (true division, always returns a float) and // (floor division, rounds toward negative infinity). % returns the remainder of floor division, and ** raises a number to a power, including fractional and negative exponents. + and * are also overloaded for sequences: concatenation for strings/lists, and repetition when multiplying a sequence by an int.
// rounds toward negative infinity, not toward zero, so -7 // 2 is -4, not -3 — this differs from integer division in languages like C, where truncation toward zero is standard.
print(7 / 2)
print(7 // 2)
print(7 % 2)
print(2 ** 10)2Practical Example
Here is a real-world application of Arithmetic Operators showing how it is used in production Python code.
print(-7 // 2)
print("ab" * 3)
print([1, 2] + [3, 4])3Best Practices
Follow these guidelines when working with Arithmetic Operators:
1. Use for exponentiation instead of importing math for math.pow(), since works natively with ints and returns an int for integer inputs
2. Remember / always returns a float, even for two ints that divide evenly
3. Watch for // rounding toward negative infinity with negative operands, not toward zero, if your logic assumes C-style truncation
Tip: // rounds toward negative infinity, not toward zero, so -7 // 2 is -4, not -3 — this differs from integer division in languages like C, where truncation toward zero is standard.
print(7 / 2)
print(7 // 2)
print(7 % 2)
print(2 ** 10)