Why Types Even Matter
A type is just a category that tells Python how a value should behave. Adding two integers means arithmetic; adding two strings means joining them; adding a string to an integer is an error. The type of a value determines what operations make sense on it.
Python has a small, friendly set of built-in types. You'll use four of them — int, float, str, bool — in nearly every program you write. The rest show up when you start organizing data into collections.
Numbers: int and float
Two kinds of numbers, and Python picks which one you get based on how you wrote it:
No decimal point? You get an int. A decimal point? You get a float. Arithmetic mixes them freely — any operation involving a float produces a float:
Integers in Python can be as big as your memory allows — no overflow, no fixed 32- or 64-bit ceiling. You can compute 2 ** 1000 and Python will hand you back every digit.
Floats follow the usual IEEE 754 rules, which means a few classic surprises:
That prints 0.30000000000000004, not 0.3. It's not a Python bug — it's how binary floating point works in every language. When you need exact decimals (money, for example), reach for the decimal module instead. For everything else, a rounding at display time is usually enough.
Strings: str
Strings are sequences of characters. Wrap them in single quotes or double quotes — Python doesn't care which, as long as the opening and closing quote match:
Triple-quoted strings (""" ... """) span multiple lines:
Strings have a huge API you'll learn over time — slicing, methods like .upper(), .split(), .replace(), and the f-string formatting that gives you f"Hello, {name}". There's a dedicated page on strings up next.
Booleans: bool
Two values, spelled exactly as shown — True and False, capital letter at the front. Comparisons produce booleans:
Under the hood, True and False are literally 1 and 0, which means you can sum booleans if you ever need to count how many conditions were true:
None: The Absence of a Value
None is Python's way of saying "no value." Functions that don't explicitly return anything return None. You'll also use it as a placeholder:
The convention is to test with is None and is not None — not == None. is checks identity, which is what you actually mean here.
Lists, Tuples, Sets, Dictionaries
These are the four built-in collection types. Each is covered in detail in its own page, but here's the quick sketch so you recognize them:
Rules of thumb:
- List: a sequence you expect to change. Adding, removing, sorting — all fine.
- Tuple: a sequence you want to protect from change. Often used for fixed-shape records like
(x, y)coordinates. - Set: a bag of unique items, when duplicates would be a bug.
- Dict: lookups by key. The JSON-shaped structure.
Converting Between Types
Python won't convert types for you automatically when that would be risky. Turning an integer into a string, or a string into a number, is something you ask for:
If a conversion doesn't make sense — int("hello"), for example — Python raises ValueError and tells you what you fed it. Error, explained, fix and move on.
Checking a Type
Two tools worth knowing:
type() is great for a quick look in the REPL. isinstance() is what you use in real code because it plays nicely with inheritance and can check against multiple types at once.
A Quick Survey Exercise
Try running the block below as-is, then change a few values and see what the types turn into:
You don't need to understand for yet — we'll get there — but this gives you a feel for the built-in types in one glance.
Pick the Type That Fits the Data
You don't need to memorize every type right now. You do need to be able to recognize one when you see it, and to pick the right one when you create data. "Is this fixed or changing? Unique or not? Do I look it up by key or by position?" Those four questions pick the collection type ninety percent of the time.
Next: strings in depth, because they're the one data type you'll touch in nearly every program.
Frequently Asked Questions
What are the main data types in Python?
Numbers (int and float), strings (str), booleans (bool), None, and four collection types — list, tuple, set, and dict. Everything else you see in Python code is built out of these plus a handful of others (bytes, complex, frozenset).
How do I check the type of a value in Python?
Wrap it in type(): type(42) returns <class 'int'>, type('hi') returns <class 'str'>. For a true/false check, use isinstance(value, int) — it's more flexible because it also handles subclasses.
Is Python statically or dynamically typed?
Dynamically typed. A variable can point to any type of value, and the same variable can change type across its lifetime. That's different from languages like Java or C++, where you declare a variable's type once and it can't change.