Module 4 · Operators — topic 1 of 16
Arithmetic operators
An overview of Python’s seven arithmetic operators (+, -, *, /, //, %, **), the types of results they produce, and how they work with integers, floats and other types.
Learning objectives
- List the seven arithmetic operators and what each does
- Predict whether a result is an int or a float
- Use unary minus and plus
Definition
An overview of Python’s seven arithmetic operators (+, -, *, /, //, %, **), the types of results they produce, and how they work with integers, floats and other types.
Introduction
An operator is a symbol that performs an operation on one or more values, called operands. In 7 + 3, the + is the operator and 7 and 3 are the operands. Arithmetic operators do maths.
Python has seven arithmetic operators. Each of the following lessons looks at one in detail; this lesson gives you the overview and the rules they share.
Why it matters
Calculations are at the heart of billing, grading, statistics, games and science. Knowing exactly what each operator returns, especially the difference between / and //, prevents some of the most common numeric bugs.
Detailed explanation
Result types: if both operands are ints, +, -, *, // and % give an int. / always gives a float. If either operand is a float, the result is a float.
Unary operators take one operand: -x negates a value, +x leaves it unchanged. -(-5) is 5.
Some operators also work on other types: + joins strings and lists, * repeats them. Operators mean whatever the operand types define, which is called operator overloading.
Arithmetic follows the familiar order from school maths: ** first, then *, /, // and %, then + and -. Parentheses override the order. The precedence lessons at the end of this module cover the full rules.
Syntax
- Binary operators sit between two operands.
- Spaces around operators are optional but improve readability.
- Unary minus is written directly before its operand.
Code examples
All seven operators
22 12 85 3.4 3 2 289
Result types
float int float
More examples
Splitting a bill
Total with tip: 2585.0 Exact share: 646.25 Rounded down share: 646.0 Left over: 1.0
Step-by-step explanation
- bill * tip_percent / 100 is 235.0, a float because / is used, so total becomes the float 2585.0.
- total / friends gives the exact share, 646.25.
- total // friends rounds down to 646.0; it is a float because total is a float.
- total % friends is the remainder after four equal whole shares: 1.0 rupee.
Expected output
Running “Splitting a bill” prints exactly:
Practical applications
- Payroll systems combine +, -, * and / to calculate gross and net pay.
- Inventory software uses // and % to pack items into full boxes and a remainder.
- Scientific code uses ** for powers, square roots (x ** 0.5) and growth formulas.
Best practices
- Put spaces around binary operators: a + b, not a+b.
- Use parentheses to make the order of a long calculation obvious.
- Pick // or / deliberately depending on whether you need a whole number.
Common mistakes
Expecting / to give a whole number
Avoid
Prefer
/ always returns a float in Python 3. Use // when you need an integer result.
Writing ^ for powers
Avoid
Prefer
^ is the bitwise XOR operator in Python, not exponentiation.
Key takeaways
- Python has seven arithmetic operators: + - * / // % **.
- / always returns a float; the others return ints for int operands.
- + and * also join and repeat strings and lists.
Try it yourself
- 1Compute how many full weeks and remaining days are in 100 days using // and %.
- 2Predict the type and value of 9 // 2.0, then check.
Finished reading? Mark it complete to update your dashboard.
Suggested practice
14 questions cover the “Operators” module. Answers and explanations are revealed after you submit.
- BeginnerWhat is printed?
- BeginnerWhat is printed?
- BeginnerWhat is printed?