Lesson 7 of 18 · 3 min
Data Types — The Different Kinds of Values Python Understands
The WHY — Why Have Different Types?
You store water in a bottle, coins in a jar, and eggs in a carton — different things need different containers. Similarly, the number 42 and the text "42" need different containers in Python because they behave differently. You can add 42 + 8, but you cannot add "42" + 8.
Python automatically figures out the type based on how you write the value — you never need to declare it.
The Core Data Types
| Type | Full Name | What It Is | Example |
|---|---|---|---|
int | Integer | Whole numbers, no decimal | 5, -3, 0, 1000 |
float | Floating Point | Numbers with a decimal point | 3.14, 99.5, -0.001 |
str | String | Text — any characters in quotes | "hello", 'Ahmed' |
bool | Boolean | Only True or False | True, False |
None | NoneType | Complete absence of a value | None |
Checking Type with type()
The type() function tells you exactly what kind of data something is:
a = 42 # a whole number b = 3.14 # a decimal number c = "hello" # text in quotes d = True # a yes/no value e = None # no value at all print(type(a)) # ask Python: what type is a? print(type(b)) # ask Python: what type is b? print(type(c)) # ask Python: what type is c? print(type(d)) # ask Python: what type is d? print(type(e)) # ask Python: what type is e?
Output: <class 'int'> <class 'float'> <class 'str'> <class 'bool'> <class 'NoneType'>
int — Whole Numbers
population = 8000000000 # 8 billion — no decimal point temperature = -15 # negative numbers work fine score = 0 # zero is an integer students = 45 # counting things always uses integers
float — Decimal Numbers
pi = 3.14159 # mathematical constant price = 99.99 # money amounts often have decimals gpa = 3.75 # grade point average tiny = 0.0001 # very small number scientific = 2.5e10 # scientific notation: 2.5 × 10^10 = 25,000,000,000
str — Strings (Text)
name = "Priya Sharma" # double quotes city = 'Chennai' # single quotes — same result as double empty = "" # empty string (zero characters) number_text = "42" # this is TEXT "42", not the number 42!
Critical insight: 42 (no quotes) is the number forty-two. "42" (with quotes) is text. Python treats them completely differently — you can do math with 42 but not with "42".
bool — True or False
is_student = True # capital T is required — True, not true has_passed = False # capital F is required — False, not false is_raining = True # booleans answer yes/no questions
None — Nothing
result = None # variable exists but contains nothing address = None # we don't have an address yet
