Numeric data types
Python's three core numeric types — int, float, and bool.
Numeric Data Types
Every value in Python has a type. In this lesson we will cover the three numeric types you will use most: int, float, and bool.
int — Integers
int represents whole numbers — positive, negative, or zero:
No Overflow
In many other programming languages, integers have a fixed size in memory, which means they can overflow — exceed their maximum value and wrap around to a wrong number. Python's int has no such limit. It grows as large as needed, limited only by your computer's memory:
This is a significant advantage in competitive programming where intermediate calculations can get very large.
float — Floating-Point Numbers
float represents real numbers with a decimal point:
Python has a single floating-point type — float — and it always gives you 64-bit double precision.
Precision Limitations
float cannot represent all real numbers exactly. This is a fundamental limitation of how computers store decimal numbers:
For competitive programming, this means you should avoid comparing floats with ==. Instead, check if the difference is small enough:
You can control how many decimal places are printed using round():
bool — Boolean Values
bool represents logical truth: either True or False. We already met booleans when working with comparison operators — every comparison returns a bool:
In Python, bool is actually a subtype of int. True equals 1 and False equals 0, which means you can use booleans in arithmetic — something that occasionally comes in handy in competitive programming:
Dynamic Typing
Python figures out the type of a variable automatically from the value you assign — this is called dynamic typing:
The same variable can hold different types at different points in the program. You can always check the current type with type():
type() works on any value — not just numbers. We will cover strings in detail in a later module, but it is good to know from the start that they are a distinct type.
Type Conversion
You can explicitly convert between numeric types:
Note that int() truncates toward zero — gives and gives . This is different from floor division which rounds toward negative infinity.