Coding/Learn/python/numbers
Python Beginner Course
01.Introduction to Python
02.Your First Python Program
03.Syntax & Indentation
04.Comments & Documentation
05.Variables
06.Core Data Types
07.Numbers & Arithmetic Operators
08.Text & Strings in Depth
09.Boolean Logic
10.Type Conversion & Casting
11.Interactive User Input
12.Assignment & Shorthand Operators
13.Comparison Operators
14.Logical Operators (and, or, not)
15.If Statements & Conditional Execution
16.If-Else Branching (Dual Paths)
17.If-Elif-Else (Multi-Path Decisions)
18.While Loops & Iteration
19.For Loops & Sequence Traversal
20.The range() Function
21.Lists & Mutable Sequences
22.Tuples & Immutable Data
23.Sets & Unique Collections
24.Dictionaries & Key-Value Stores
25.List Indexing & Slicing
26.Essential List Methods
27.Essential String Methods
28.Functions & Modular Code
29.Function Parameters & Arguments
30.Return Values & Data Flow
31.Exception Handling (try / except)
32.Capstone Mini-Projects
Course Certificate0%

Complete all lessons to earn

LearnNumbers & Arithmetic Operators
7 / 32 0%
Lesson 07 of 32
6 mins read

Numbers & Arithmetic Operators

PreviousNext Lesson
In Plain English

Computers are fundamentally calculators on rocket fuel. Python comes with full arithmetic support out of the box: addition, subtraction, multiplication, decimal division, floor division, modulo (remainder), and exponents.

The Mental Model

"Standard math operators work just like your school calculator. The extra superpowers are // (floor division: tells you how many whole pizzas everyone gets) and % (modulo: tells you how many slices are left over)."

Deep Dive: How It Works

Basic math: + (addition), - (subtraction), * (multiplication), / (standard division). Note that / always produces a float result in Python 3 (e.g. 10 / 2 gives 5.0).

Floor Division (//): Divides two numbers and chops off any decimal remainder, returning the largest integer (e.g. 7 // 2 gives 3).

Modulo (%): Returns the remainder of division (e.g. 7 % 2 gives 1). Super useful for checking if a number is even (num % 2 == 0) or cycling through items.

Exponentiation (**): Raises a number to a power (e.g. 2 ** 3 is 2 cubed = 8). Note: Python uses ** for powers, not ^ (which is bitwise XOR).

Order of Operations: Python strictly follows PEMDAS (Parentheses, Exponents, Multiplication/Division, Addition/Subtraction). Use parentheses ( ) to clarify your intent.

Syntax Blueprint

result = 10 + 5    # Add (15)
result = 10 // 3   # Floor divide (3)
result = 10 % 3    # Remainder (1)
result = 2 ** 4    # Power (16)

Standard arithmetic symbols with // for integer division and ** for power.

PointCore Rules to Remember

Point star
Division Always Floats: The / operator always returns a float (e.g. 4 / 2 is 2.0).
Point star
Modulo for Remainders: % gives you the leftover after division. Great for checking even/odd.
Point star
Use ** for Powers: In Python, 3 ** 2 is 9. Do not use 3 ^ 2 for exponents.

Common Beginner Traps & How to Fix Them

Mistake:Using ^ for exponentiation: 2 ^ 3

Why it happens: In math notation ^ means power, but in Python ^ is the bitwise XOR operator (2 ^ 3 = 1).

How to fix: Always use double asterisks ** for power calculations (2 ** 3 = 8).

Pro Tip: You can write large numbers with underscores for readability: one_million = 1_000_000. Python ignores the underscores!

Live Interactive Example

Hit Run Code to see it live
Python Math Showcase
Python 3.12
1
2
3
4
5
6
7
Output Console
Click "Run Code" to view the rendered output.
How it works: Notice how floor division (//) gave 2 instead of 2.5, and modulo (%) gave 2 as the remainder.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Calculate remaining cookies

  • PointYou have 23 cookies and want to split them equally among 4 friends.
  • PointUse the modulo operator % to calculate and print the remaining cookies.
1
2
3
4
Sandbox Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates