Fundamentals 6 min read

Master Python’s Built‑In Numeric Types: From Integers to Complex Numbers

This article explains Python’s built‑in numeric objects—including integers, longs, floats, scientific notation, binary/octal/hex literals, fractions, boolean values, and complex numbers—while highlighting key differences between Python 2 and Python 3 arithmetic behaviors.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Master Python’s Built‑In Numeric Types: From Integers to Complex Numbers

Python is an object‑oriented language where everything can be treated as an object. Built‑in objects are divided into simple types (numeric data) and container types (sequences, tuples, mappings, etc.).

Simple numeric types include integer ( int), long integer ( long), floating‑point ( float), complex ( complex) and boolean ( bool) values.

Container types include sequences such as strings, lists and tuples, and the mapping type dict. The special object None represents the empty value.

All objects have attributes and built‑in methods, which are accessed with the dot operator ( .).

1. Constants

Python numeric literals support decimal, binary ( 0b), octal ( 0o) and hexadecimal ( 0x) formats, as well as scientific notation (e.g., 1.2e-3). Fractions and complex numbers are also valid literals.

2. Fractions

The Fraction(x, y) function from the fractions module creates a rational number representing x/y. Before using it, import the module. Float strings can also be converted to fractions.

3. Boolean

Boolean objects have only two values: True and False. Empty data types evaluate to False. Booleans are commonly used in conditional statements, loops, and branch logic.

4. Complex Numbers

Complex numbers consist of a real part and an imaginary part, the latter indicated by the suffix j or J. They support the usual arithmetic operations, and results of operations between complex numbers remain complex.

Python also distinguishes division behavior between versions: in Python 2, the division operator / performs integer division when both operands are integers, while in Python 3 it always returns a floating‑point result. The floor division operator // yields the largest integer less than or equal to the true quotient, and the modulo operator % returns the remainder.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonbooleanConstantsnumeric typescomplex numbersfractions
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.