1.1.1 Numeric Data Types (int / float / complex)
Python provides several built-in numeric data types to represent numbers.
The most commonly used ones are integers, floating-point numbers, and complex numbers.
Understanding numeric data types is essential because they directly affect how calculations are performed and how results are stored.
Integer (int)
An integer represents whole numbers without a decimal point.
Examples:
- Positive numbers:
1,42 - Negative numbers:
-7 - Zero:
0
Integers in Python can be arbitrarily large and are not limited by fixed sizes.
Floating-Point Number (float)
A floating-point number represents real numbers with a decimal point.
Examples:
3.14-0.0012.0
Floating-point numbers are commonly used in scientific and engineering calculations, but they may introduce small precision errors due to how they are stored internally.
Complex Number (complex)
A complex number consists of a real part and an imaginary part.
Example format:
a + bj
Examples:
3 + 4j1j
Complex numbers are mainly used in advanced mathematics, physics, and signal processing.
📌 Note:
In most beginner programs,intandfloatare used far more often thancomplex.