Basic Data Types
Python's core built-in types -- int, float, str, bool, and None -- and how to check them.
2 min read
Every value in Python has a type, even though you never declare it explicitly. Knowing the core built-in types — and their quirks — is the foundation everything else in the language builds on.
Numbers: int and float
whole = 10 # int
decimal = 3.14 # floatint handles whole numbers with no size limit (Python automatically switches to arbitrary-precision arithmetic, so you'll never hit an integer overflow). float handles decimals, using the same 64-bit floating-point representation most languages use — which means the classic floating-point rounding quirk applies here too:
print(0.1 + 0.2) # 0.30000000000000004This isn't a Python bug; it's how binary floating-point math works everywhere. For money or anything requiring exact decimal precision, use the decimal module instead of raw floats.
Strings
greeting = "Hello"
name = 'Ada'
multiline = """This spans
multiple lines"""Single and double quotes work identically — pick one and be consistent, or use double quotes when the string itself contains an apostrophe. Triple quotes (""" or ''') create multi-line strings, commonly used for docstrings (documentation attached to functions and classes, covered later).
Booleans
is_ready = True
is_done = FalseTrue and False are capitalized in Python — unlike JavaScript's true/false. Booleans are technically a subtype of integers (True == 1 and False == 0 both evaluate to True), a quirk that rarely matters but occasionally explains surprising behavior.
None
None represents the deliberate absence of a value — Python's equivalent of null:
result = NoneA function with no explicit return statement returns None automatically. Always compare against it with is None, not == None:
if result is None:
print("Nothing here yet")is checks that two names point to the exact same object, which matters because None is a true singleton — there's only ever one None in a running Python program.
Checking a value's type
print(type(42)) # <class 'int'>
print(type("hi")) # <class 'str'>
print(type(3.14)) # <class 'float'>type() returns a value's exact type, useful for debugging when a variable doesn't behave the way you expect. The next lesson covers converting between these types deliberately, and the one after that covers formatting them into readable strings.
Test what you just learned
4 quick questions. Get all of them right to unlock the next lesson.
You can take the quiz without an account — logging in just lets your result count toward your progress.