Skip to content

Primitive Data Types

In Python, every value is an Object. Even a simple number like 5 has its own methods and internal state. The “Type” of an object determines what it represents, how much memory it consumes, and what operations (like addition or slicing) are valid for it.

In this lesson, we explore the scalar (primitive) types that serve as the building blocks for all complex Python programs.


Integers represent whole numbers, positive or negative, without a fractional component.

Unlike languages like C or Java, where an int is typically limited to 32 or 64 bits, Python integers have arbitrary precision. This means an integer can be as large as your computer’s RAM allows.

massive_integer.py
# A standard integer
x = 100
# A massive integer (2 to the power of 512)
huge_num = 2 ** 512
print(huge_num)

How does Python store a number that is thousands of digits long? A Python int is a C struct that contains:

  1. ob_refcnt: Reference count.
  2. ob_type: Pointer to the int type object.
  3. ob_size: The number of “digits” (Python uses base-2^30 for internal math).
  4. ob_digit: An array of digits that make up the large number.

Any number with a decimal point is a float. Python follows the IEEE 754 double-precision standard.

gravity = 9.81
scientific = 1.5e-3 # 0.0015

Computers use binary (Base-2) to represent decimals. Some Base-10 decimals (like 0.1) cannot be represented perfectly in binary.

precision.py
print(0.1 + 0.2 == 0.3) # Output: False!
print(0.1 + 0.2) # Output: 0.30000000000000004

Context: For financial or high-precision scientific code, never use floats for exact equality. Use the decimal module instead.


Booleans represent truth values: True and False.

In Python, bool is a subclass of int.

  • True is essentially the integer 1.
  • False is essentially the integer 0.
print(True + 5) # Output: 6

While this works, you should never perform math on booleans. It is a legacy behavior from early versions of Python that is preserved for compatibility.


None is a special constant used to represent the absence of a value. It is the only instance of the NoneType class.

Always use the is operator when checking for None, not ==.

result = None
if result is None:
print("No data received.")

Why is? Because is checks Identity (is this the exact same object in memory?), and there is only ever one None object in a running Python program. This is faster and safer than ==.


TypeClassMutabilityExample
IntegerintImmutable42, -1
FloatfloatImmutable3.14, 2.0
BooleanboolImmutableTrue, False
NoneNoneTypeImmutableNone