What is the difference between a naive and an aware `datetime` object, and why does mixing them raise a `TypeError`?
Answer
A naive `datetime` has no attached timezone information at all — it is just a plain point on a calendar with no way to know what timezone it represents — while an aware `datetime` carries a `tzinfo` object that anchors it to a specific offset from UTC. Comparing a naive and an aware datetime for equality or inequality (`==`, `!=`) does not raise: Python simply treats them as unequal, since it has no basis to consider them the same instant. Ordering comparisons (`<`, `>`, `<=`, `>=`) and subtraction do raise `TypeError: can't compare offset-naive and offset-aware datetimes`, because there is genuinely no correct answer for what "earlier" or "how far apart" should mean without knowing the naive value's implied timezone, and silently guessing would produce data corruption for global applications instead of a loud, catchable error.
Strong answer includes
- naive datetime has no attached timezone at all
- aware datetime carries a tzinfo anchoring it to a UTC offset
- == and != between naive and aware just compare unequal; ordering and subtraction raise TypeError instead of guessing
Practical example
datetime.now()returns a naive datetime in the server's local time, while
datetime.now(timezone.utc)returns an aware one; subtracting one from the other raises `TypeError` instead of producing a subtly wrong duration.