Identity Determines Behavior
In physical reality, you cook rice to eat, but you read a book to learn—you cannot eat a book or read a bowl of rice. In programming, numbers can be multiplied or subtracted, but textual sentences cannot be divided. What you are permitted to do with any piece of data is strictly dictated by its Data Type.
01 What Truly is a Data Type?
Stated simply and definitively:
A Data Type is a classification that tells the compiler or runtime what kind of value an expression represents, how it is stored in physical memory, and which operations can legally be performed upon it.
For example:
Both values occupy memory in your machine, but their binary encoding and behavioral capabilities are entirely distinct.
02 Why Do Data Types Matter? (25 vs. "25")
Observe these two expressions carefully:
The exact same plus operator (+) produces completely different results based on the types involved! For numbers, it executes mathematical addition. For strings, it fuses the text sequences together (concatenation). Failing to track data types is a prime source of critical arithmetic bugs in production software.
03 Python's 5 Fundamental Primitive Data Types
To start building practical applications, you must master these five foundational types:
25, -10, 0).99.5, 3.1416, -0.5)."Salim", 'Dhaka').True or False.None).04, 05 & 06 Numbers: Integer vs. Float
Numeric computation in Python divides primarily into discrete counts (int) and real measurements (float):
While they share mathematical equivalence, their machine representations are completely different! 10 is an <class 'int'>, whereas 10.0 is a <class 'float'>. Floats are structured in memory following the IEEE 754 standard, segmented into sign, exponent, and mantissa bits.
07 & 08 String — Textual Data
Any sequence of characters wrapped within quotation marks is a String. Python supports both single and double quotes interchangeably:
score = 100 is an integer. But if you mistakenly write score = "100", Python considers it plain text. Attempting to add numbers to it directly will cause an immediate crash.
09 & 10 Boolean — Truth and Decision-Making
Software constantly evaluates questions of truth. To represent truth states, Python provides the Boolean type. A boolean can take only two values: True or False (capitalization is mandatory):
Every modern software system asks questions: Is the session active? Does the user have admin privileges? Has the checkout payment cleared? Each answer maps cleanly to a boolean flag. In upcoming lessons on control flow (if/else), booleans will govern every decision your program makes.
11 & 12 `None` — The Explicit Absence of Value
Often, a variable must be defined before its value is known (e.g., an optional middle name field that the user left blank). Python represents this state using None:
These 4 values mean completely different things:
13, 14 & 15 The `type()` Function & Dynamic Typing
Python is a Dynamically Typed Language. The runtime automatically infers types from assigned values without explicit type declarations. To inspect the underlying type of any variable or expression, Python offers the built-in type() function:
16 & 17 Incompatible Combinations: `TypeError`
If you attempt an operation between types that have no logical compatibility, Python halts with a TypeError:
Python explains clearly: “You cannot concatenate an integer directly to a string!” To resolve this, we employ Type Conversion.
18 to 22 Type Conversion (Type Casting)
Converting a value from one data type into another is known as Type Conversion or Type Casting. Python provides straightforward conversion functions:
Executing int("hello") causes Python to throw ValueError: invalid literal for int() with base 10: 'hello'. You cannot parse arbitrary alphabetic letters into base-10 numbers. The source string must contain valid numeric digits.
23 Real-World Example: Web Form Data Ingestion
When web applications receive user inputs via HTTP forms or REST APIs, the data arrives almost universally as raw Strings:
Salim next year: 26
Balance after fee: 1300.5
24 Connection to Computer Science Foundations
Recall from Course 01: at the transistor level, hardware recognizes only patterns of 0s and 1s. The CPU does not inherently know whether a sequence of 32 bits is an integer, an IEEE float, a slice of an image, or an ASCII character.
The high-level Data Type abstraction attaches meaning to raw bits, directing the Python VM which machine operations to invoke:
25 & 26 The 5 Core Types at a Glance & A Critical Warning
27 Today's Mental Model
28 Hands-On Practice Challenges
Open datatypes_practice.py in your editor and complete these exercises:
True/False), and phone number (None). Print each variable alongside its type().
int(), float(), and str(), observing which succeed and which fail:
val2 = "50.5"
val3 = 100
val4 = 100.0
print("50" + "50") with print(int("50") + int("50")) and analyze the divergent outcomes.
29 🧠 Key Takeaways & Summary
int (whole numbers), float (decimals), str (text), bool (truth states), and NoneType (absence of value).int(), float(), str(), or bool().Next Lesson: Input, Output & Type Conversion
So far, all program data has been hardcoded in source files. How do programs accept live, interactive input from terminal users and transform it for dynamic computations?