Data Types
Data Types
🎯 By the end of this lesson
After reading this lesson, you will be able to confidently do the following three things.
- ▸✅ 8 types: int · float · str · bool · list · tuple · dict · set
- ▸✅ mutable vs immutable (list ↔ tuple, dict ↔ frozenset)
- ▸✅ Type hint notation (int, str, list[int])
Keep the learning objectives as a checklist, and close the lesson once you can answer all of them.
5 Python Data Types — Code + Output
In Python, every value is an object. You can check the type of any value with type().
1. int — Integer (unbounded)
Other languages like Java and C limit int to 32-bit or 64-bit, but Python integers are unlimited up to available memory.
2. float — Floating-point number
Why 0.1 + 0.2 ≠ 0.3: computers use binary, so they cannot represent decimal fractions exactly. Use the Decimal module for financial calculations.
3. str — String (Unicode)
+ is for concatenation, is for repetition*.
4. bool — True / False
5. None — The absence of a value
If a function has no return statement, it automatically returns None. Similar to null in JavaScript.
6. Type Conversion (Casting)
```python
# String → Number
age_str = "28"
age = int(age_str) # 28
print(age + 1) # 29
# Number → String
score = 95
print("Score: " + str(score)) # "Score: 95"
# Trap — Decimal string cannot be directly converted to int()
# int("3.14") → ValueError
print(int(float(
🐍 Run It — Data Types
🤖 Try asking AI like this
Knowing the concepts in this lesson lets you give AI specific instructions. Instead of a vague 'fix this,' you make vocabulary-driven requests — and that's where token savings start.
- ▸'Refactor this dict logic into a dataclass'
- ▸'Add type hints to these variables'
Why this reduces tokens
Without knowing the concepts, you have to ask 'What does that mean?' again after receiving the AI's answer. That follow-up question is what burns tokens. Learn the concept once, and the conversation ends in one round.