Arithmetic Operators

Python · Operators

Theory

Arithmetic operators do math on numbers: + add, - subtract, * multiply, / true division, // floor division, % remainder (modulo) and ** power. Python applies precedence like school maths: ** first, then unary minus, then *, /, //, %, and finally + and -. Parentheses override everything, so price * (1 - 0.1) subtracts before multiplying. ** groups from the right, so 2 ** 3 ** 2 is 2 ** 9 = 512, and -2 ** 2 is -4 because the power happens before the minus.

Types matter: / always returns a float, // rounds down to the nearest whole number, and % returns a remainder with the same sign as the divisor (-7 % 3 is 2). divmod(a, b) gives both quotient and remainder at once. Several operators also work on other types: + joins strings and lists, and * repeats them ('ab' * 3 is 'ababab').

Why we use it

Every metric in analytics, from totals and averages to discounts and growth rates, is built from arithmetic. Knowing precedence and the exact behaviour of /, // and % prevents silent calculation mistakes.

When to use it

Use % to test even/odd (n % 2 == 0) or to wrap values into a range, // to split items into whole groups, and ** for powers and compound growth. Add parentheses whenever precedence is not obvious to a reader.

How it works

  1. Python meets price * (1 - 0.1)
  2. Evaluate anything inside parentheses first: 1 - 0.1 = 0.9
  3. Apply ** next, then * / // %, then + -
  4. Are both operands int and the operator not /? Yes: Result stays an int. No: Result becomes a float.
  5. Output: 90.0

Syntax

+  -  *  /  //  %  **

Example

price = 100
discounted = price * (1 - 0.1)

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic