int() / float()
Converts text/a number to an integer or float.
Syntax
int(value) · float(value)
Description
int() converts to an integer, float() to a float. It's essential for turning input() text into a number. Text that can't be converted raises an error.
Returns
The converted number.
Example
Loading editor…
Expected output
50 7.0 9
When to use?
Taking text coming from the user/a file into a calculation.
Common mistakes
- ⚠️ int("3.5") raises an error; use float("3.5") first, then int().
- ⚠️ int() cuts off the decimal downward; it doesn't round.