Free ATS Friendly Resume Builder Online

Create Your Resume

Resume Builder

Resume Maker

Resume Templates

Resume PDF Download

Create Your Resume is a free online resume builder that helps job seekers create professional, ATS friendly resumes in minutes. Easily build, customize, and download modern resume templates in PDF format.

Our resume maker is designed for freshers and experienced professionals looking to create job-ready resumes. Choose from multiple resume templates, customize sections, and generate ATS optimized resumes online for free.

Create resumes for IT jobs, software developers, freshers, experienced professionals, managers, and students. This free resume builder supports CV creation, resume PDF download, and online resume editing without signup.

Back to Python
Lesson 6 of 17

What Are Numeric Data Types in Python? int, float, and complex Explained Clearly

Numeric data types in Python—int, float, and complex—are used to store and manipulate numbers in different forms. They are fundamental to almost every Python program, from simple calculations to advanced scientific computing, data analysis, game development, and financial systems. Python makes working with numbers intuitive by automatically choosing the correct numeric type based on the value you assign. You don’t need to declare whether a number is an integer or a decimal—Python infers it for you. This flexibility speeds up development, but understanding how each numeric type behaves is essential to avoid precision errors, incorrect comparisons, and performance issues. This topic explains Python’s numeric data types from the ground up. You’ll learn what each type represents, how Python stores and operates on numbers, when to use each numeric type, and common pitfalls developers face in real-world applications.

Overview of Numeric Data Types in Python

Python provides built-in numeric data types to represent different kinds of numbers. These types are part of Python’s core and require no imports.

The three primary numeric data types are:

  • int – whole numbers
  • float – decimal (floating-point) numbers
  • complex – numbers with real and imaginary parts

The int Data Type (Integers)

The int type represents whole numbers, both positive and negative, without any decimal point.

Examples of Integers

a = 10
b = -25
c = 0

Python integers have arbitrary precision, which means they can grow as large as memory allows.

Large Integer Example

big_number = 123456789012345678901234567890

Unlike many languages, Python does not overflow integers.

Common Uses of int

  • Counting and indexing
  • Loop iterations
  • User IDs and quantities
  • Discrete calculations

The float Data Type (Floating-Point Numbers)

The float type represents numbers with decimal points. Internally, Python uses binary floating-point representation.

Examples of Floats

price = 99.99
temperature = -3.5
ratio = 1.0

Floating-Point Precision Issue

Not all decimal values can be represented exactly in binary. This can lead to small precision errors.

print(0.1 + 0.2)

The output may be:

0.30000000000000004

When to Use float

  • Measurements
  • Scientific calculations
  • Percentages and ratios
  • Approximate values

The complex Data Type

The complex type represents numbers with a real and an imaginary part.

A complex number is written as:

a + bj

Where j represents the imaginary unit.

Complex Number Examples

z1 = 2 + 3j
z2 = -1.5 + 0.5j

Accessing Parts of a Complex Number

print(z1.real)
print(z1.imag)

Common Uses of complex

  • Scientific computing
  • Signal processing
  • Electrical engineering
  • Mathematical modeling

Type Conversion Between Numeric Types

Python allows explicit conversion between numeric types.

x = int(3.7)
y = float(5)
z = complex(2)

Conversions follow predictable rules:

  • float to int truncates the decimal part
  • int to float adds a decimal
  • complex must be created explicitly

Numeric Operations Across Types

Python supports operations between different numeric types.

result = 5 + 2.5
print(result)

Python automatically promotes the result to the more general type (float in this case).

Numeric Type Hierarchy

Python follows a numeric hierarchy:

int → float → complex

Operations move upward in this hierarchy to avoid loss of information.

Checking Numeric Types

x = 10
print(type(x))
print(isinstance(x, int))

Performance and Memory Considerations

  • int is generally faster for exact arithmetic
  • float uses fixed-size memory
  • complex consumes more memory

Choosing the right numeric type improves both accuracy and performance.

Common Mistakes Beginners Make

  • Comparing floats for exact equality
  • Ignoring precision errors
  • Assuming int has size limits
  • Using float for financial calculations

Real-World Example

A billing application uses integers for item counts, floats for tax calculations, and avoids floating-point errors in currency by applying proper rounding strategies. Scientific software, on the other hand, may rely heavily on complex numbers for signal analysis and simulations.

Numeric Data Types Comparison

Type Represents Precision Common Use
int Whole numbers Exact Counting, indexing
float Decimal numbers Approximate Measurements, ratios
complex Real + imaginary Exact components Scientific computing

Summary

Python’s numeric data types—int, float, and complex—provide flexible and powerful ways to work with numbers. Integers offer exact arithmetic, floats handle real-world measurements, and complex numbers enable advanced mathematical modeling. Understanding how these types behave, interact, and differ is essential for writing correct, efficient, and reliable Python programs. These fundamentals form the backbone of almost every Python application.