Lesson 04 of 55
9 mins readPython Arithmetic, Precedence & Infix Functions
In Plain English
Haskell strictly differentiates floating point division (/) from integer division (div). Prefix functions with two arguments can be used as infix operators with backticks (`div`).
Deep Dive: How It Works
Division Differences: / is only for fractional types (Float, Double); use div for integer quotient and mod for remainder.
Infix Backticks: Any 2-argument function foo a b can be written as an infix operator: a `foo` b (e.g. 10 `div` 3).
Negative Numbers: Wrap negative literals in parentheses (e.g. 5 + (-2)) to avoid ambiguity with the minus operator.
Core Rules to Remember

Floating (/) vs Integer (`div`): Use / for fractional division and `div` for integer truncation.

Backtick Infix Notation: 10 `mod` 3 is equivalent to mod 10 3.
Live Interactive Example
Hit Run Code to see it liveArithmetic and Infix Operations
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
Output Console
Click "Run Code" to view the rendered output.
How it works: 17 `div` 5 gives integer quotient 3 with remainder 2.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Calculate Integer Modulo
Compute `100 `mod` 7` and print `"Remainder: "` followed by its `show` string.
1
2
3
4
5
6
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.