My Notes
Python Data Types - The Complete Breakdown
Python Data Types — The Complete Breakdown
So what even is a data type?
When you store something in a variable, Python doesn't just save the value — it also tracks what kind of thing it is. A name is different from a number. A number with decimals is different from a whole number. A yes/no answer is different from both.
That's a data type. It tells Python how to store the value, what operations make sense on it, and what you're allowed to do with it.
Python figures out the type automatically when you assign a value — you don't have to declare it like some other languages. But you still need to know what type you're working with, or you'll get errors that feel confusing until they suddenly make total sense.
You can always check the type of anything using type():
x = 42
print(type(x))
Output:
<class 'int'>
Alright. Let's go through every single one.
The core four — you'll use these every day
1. str — String (text)
Any text. Anything wrapped in single quotes '...' or double quotes "..." is a string. Doesn't matter which you use, just be consistent.
name = "Kalyan"
language = 'Python'
empty = ""
print(type(name))
Output:
<class 'str'>
Strings are sequences — meaning every character has a position (index), starting from 0.
word = "hello"
print(word[0])
print(word[-1])
Output:
h
o
Negative index counts from the end. -1 is always the last character.
Common string operations:
s = "hello world"
print(s.upper()) # HELLO WORLD
print(s.capitalize()) # Hello world
print(s.replace("world", "Python")) # hello Python
print(len(s)) # 11
print(s.split(" ")) # ['hello', 'world']
One important thing: "42" is NOT the same as 42. The first is a string (text that looks like a number), the second is an actual integer. Python will not treat them the same way.
2. int — Integer (whole numbers)
Any whole number, positive or negative, no decimal point.
age = 22
score = -5
big = 1000000
print(type(age))
Output:
<class 'int'>
Python integers have no size limit — they can be as big as your memory allows. No overflow errors like some other languages.
Math works exactly as expected:
a = 10
b = 3
print(a + b) # 13
print(a - b) # 7
print(a * b) # 30
print(a ** b) # 1000 (exponentiation — 10 to the power of 3)
print(a // b) # 3 (floor division — rounds down)
print(a % b) # 1 (modulo — the remainder)
The // and % operators trip people up at first. // gives you the quotient without the decimal. % gives you what's left over. So 10 // 3 is 3 (three 3s fit into 10), and 10 % 3 is 1 (1 is left over).
3. float — Floating point (decimal numbers)
Any number with a decimal point. Even 10.0 is a float, not an int.
price = 9.99
pi = 3.14159
temp = -2.5
print(type(price))
Output:
<class 'float'>
print(10 / 3) # 3.3333333333333335 (regular division always returns float)
print(10 // 3) # 3 (floor division returns int)
One thing to know: floats aren't perfectly precise in computers. This is a fundamental computer science limitation, not a Python bug.
print(0.1 + 0.2)
Output:
0.30000000000000004
Yeah. That's real. If you need exact decimal precision (like for money), use the decimal module — but that's advanced territory, don't worry about it now.
4. bool — Boolean (True or False)
The simplest type. Only two possible values: True or False. Capital T and F — that matters.
is_logged_in = True
has_errors = False
print(type(is_logged_in))
Output:
<class 'bool'>
Booleans come from comparisons:
age = 22
print(age > 18) # True
print(age == 30) # False
print(age != 30) # True
Under the hood, True is just 1 and False is just 0 in Python. So this works:
print(True + True) # 2
print(False + 1) # 1
Weird, but useful to know.
The containers — for storing multiple values
5. list — Ordered, changeable collection
A list holds multiple values in order, inside square brackets []. You can mix types, change values, add or remove items.
scores = [95, 87, 72, 100]
mixed = [1, "hello", True, 3.14]
print(type(scores))
print(scores[0]) # 95 (first item, index 0)
print(scores[-1]) # 100 (last item)
Output:
<class 'list'>
95
100
Modifying a list:
fruits = ["apple", "banana", "cherry"]
fruits.append("mango") # add to end
fruits.remove("banana") # remove by value
fruits[0] = "grape" # change by index
print(fruits)
Output:
['grape', 'cherry', 'mango']
6. tuple — Ordered, unchangeable collection
Like a list, but locked. Once you create it, you can't change it. Uses parentheses ().
coordinates = (19.0760, 72.8777)
rgb = (255, 0, 128)
print(type(coordinates))
print(coordinates[0])
Output:
<class 'tuple'>
19.076
Why use a tuple over a list? When the data should never change — like GPS coordinates, RGB color values, days of the week. It also runs slightly faster than a list.
If you try to change a value:
coordinates[0] = 0 # TypeError: 'tuple' object does not support item assignment
Python will stop you.
7. dict — Dictionary (key-value pairs)
A dictionary stores data as pairs — a key and its value — inside curly braces {}. Think of it like a real dictionary: you look up a word (key) to get its definition (value).
person = {
"name": "Kalyan",
"age": 22,
"language": "Python"
}
print(type(person))
print(person["name"])
print(person["age"])
Output:
<class 'dict'>
Kalyan
22
Adding, updating, and removing:
person["city"] = "Boston" # add new key
person["age"] = 23 # update existing key
del person["language"] # delete a key
print(person)
Output:
{'name': 'Kalyan', 'age': 23, 'city': 'Boston'}
8. set — Unordered collection of unique values
A set is like a list but it automatically removes duplicates and has no guaranteed order. Uses curly braces {} like a dict, but with just values (no keys).
tags = {"python", "security", "python", "code", "security"}
print(type(tags))
print(tags)
Output:
<class 'set'>
{'code', 'python', 'security'}
The duplicates got removed automatically. Order is not guaranteed — don't rely on it.
Useful for checking membership fast and doing set operations:
a = {1, 2, 3, 4}
b = {3, 4, 5, 6}
print(a & b) # {3, 4} intersection — what's in both
print(a | b) # {1, 2, 3, 4, 5, 6} union — everything
print(a - b) # {1, 2} difference — in a but not b
The nothing type
9. NoneType — None (the absence of a value)
None means "nothing" or "no value". It's not zero, not an empty string — it's the actual absence of a value. Every function in Python returns None if you don't explicitly return something.
result = None
print(type(result))
print(result)
Output:
<class 'NoneType'>
None
You'll see it a lot when something isn't set yet, or a function has nothing to return.
def do_nothing():
pass
x = do_nothing()
print(x) # None
To check for None, always use is, not ==:
if result is None:
print("No value yet")
Type conversion — switching between types
Python lets you convert between types manually. This comes up constantly.
# string to int
age = int("22")
# int to string
label = str(100)
# string to float
price = float("9.99")
# int to float
x = float(5) # 5.0
# float to int (truncates — doesn't round)
y = int(3.99) # 3
# anything to bool
print(bool(0)) # False
print(bool(1)) # True
print(bool("")) # False
print(bool("hi")) # True
print(bool([])) # False
print(bool([1,2])) # True
The bool conversions are useful to know. In Python, empty things (0, "", [], {}, None) are all "falsy" — they evaluate to False. Non-empty things are "truthy" — they evaluate to True.
The full reference — all types at a glance
| Type | Category | Example | Mutable? |
|---|---|---|---|
str | Text | "hello" | No |
int | Number | 42 | No |
float | Number | 3.14 | No |
bool | Boolean | True | No |
list | Container | [1, 2, 3] | Yes |
tuple | Container | (1, 2, 3) | No |
dict | Container | {"key": "val"} | Yes |
set | Container | {1, 2, 3} | Yes |
NoneType | Nothing | None | No |
Mutable means you can change it after creation. Immutable means once it's made, it's locked.
The one-line summary
Python has one type for text (str), two for numbers (int, float), one for yes/no (bool), three containers for storing multiple values (list, tuple, dict), one for unique collections (set), and one for nothing (None). Know what type you're working with, and half your bugs disappear before they happen.