Python Data Types Overview

In the last lesson you learned f-Strings. That is a clean way to drop values into text. But what kinds of values can you put in a variable in the first place? A whole number? Some text? A list of things? A yes-or-no answer? Python has a built-in type for each of these. Knowing the full set early gives you a map before we zoom into each one later.

🤔 Why Data Types Matter

Here is the pain. You write some code. It looks fine. Then Python throws an error like can only concatenate str (not "int") to str. What happened? You tried to glue text and a number together. Python refused because they are different kinds of values.

The fix is to understand data types. A data type is simply the kind of value something is. Is it a number? Is it text? Is it a true/false answer? Once you know the kind, you know what you can do with it. Numbers can be added. Text can be joined. Lists can be looped over. Each type comes with its own set of things you can do.

Think of it like a kitchen. A knife, a spoon, and a pot are all tools. But each one is for a different job. You would not stir soup with a knife. In the same way, each data type in Python is for a different job.

🧩 The Main Built-in Types

Python ships with a handful of built-in types you will use every day. Here is the full map. Do not worry about memorizing it. Each one gets its own lesson later, so this is just the overview.

Type What it holds Tiny example
int Whole numbers, no decimal point age = 25
float Numbers with a decimal point price = 9.99
str Text, written inside quotes name = "Riya"
bool A true or false answer is_open = True
list An ordered collection you can change colors = ["red", "blue"]
tuple An ordered collection you cannot change point = (3, 4)
set A collection of unique items, with no fixed order tags = {"a", "b"}
dict Pairs of keys and values, like a labelled box user = {"name": "Alex"}
NoneType The “nothing here yet” value result = None

You do not need all of these on day one. You will mostly start with numbers, text, and true/false. The collections (list, tuple, set, dict) come in when you need to hold many things at once.

🔢 Numbers, Text, and True/False

Let’s look at the everyday three first. These cover most of what a small program does.

This snippet makes one value of each basic type and prints it.

age = 25 # int: a whole number
price = 9.99 # float: a number with a decimal
name = "Riya" # str: text inside quotes
is_member = True # bool: True or False
print(age)
print(price)
print(name)
print(is_member)

Output

25
9.99
Riya
True

Going line by line:

  • age = 25 has no decimal point, so Python calls it an int, short for integer.
  • price = 9.99 has a decimal point, so it is a float. The name comes from “floating point”. That just means the decimal can be anywhere.
  • name = "Riya" is wrapped in quotes, so it is a str, short for string. A string is just a piece of text.
  • is_member = True is a bool, short for boolean. A boolean is only ever True or False, with capital first letters in Python.

Now the why. Python decides the type for you based on how you write the value. You do not announce the type up front. Quotes mean text. A decimal point means float. The bare words True and False mean boolean.

📦 Collections: Holding Many Things

The basic types hold one value. Often you need to hold a group. That is what the collection types are for.

This snippet shows the four collection types side by side.

colors = ["red", "green", "blue"] # list: ordered, changeable
point = (3, 4) # tuple: ordered, fixed
unique_tags = {"python", "code"} # set: unique items only
user = {"name": "Alex", "age": 30} # dict: key -> value pairs
print(colors)
print(point)
print(sorted(unique_tags))
print(user)

Output

['red', 'green', 'blue']
(3, 4)
['code', 'python']
{'name': 'Alex', 'age': 30}

A set has no fixed order. So if you print the set on its own, your items may come out in a different order than someone else’s. That is normal. Here we wrap it in sorted() so the output is the same every time. Now here is the plain-English version of each collection:

  • A list uses square brackets [ ]. It keeps its order. You can add, remove, or swap items later. Think of a shopping list you keep editing.
  • A tuple uses round brackets ( ). It also keeps order. But once you make it, you cannot change it. Think of a pair of coordinates that should stay fixed.
  • A set uses curly brackets { } with plain items. It throws away duplicates and keeps only unique values. Think of a guest list where each name appears once.
  • A dict, short for dictionary, also uses curly brackets { } but stores pairs. Each item has a key and a value, like name points to Alex. Think of a contact card with labels.

Note

A set and a dict both use curly brackets, so how does Python tell them apart? A dict has those key-value pairs joined by a colon, like "name": "Alex". A set just has plain items. Each gets its own lesson later, so this is only the quick view.

🕳️ None: The Empty Value

Sometimes you want a variable to exist but hold nothing yet. For that Python has a special value called None.

This snippet sets a result to nothing, then fills it in later.

result = None # nothing here yet
print(result)
result = 42 # now it holds a real value
print(result)

Output

None
42

None is not zero. It is not an empty string either. It is Python’s way of saying “no value at all, on purpose”. You will see it a lot when a function has nothing to give back. You will also see it when you set up a variable before you know its real value. Its type is NoneType.

🔍 Checking a Type with type()

So you have a value and you are not sure what kind it is. Python gives you a built-in tool called type() that tells you straight away.

You pass any value into type() and it reports the type back.

print(type(25)) # int
print(type(9.99)) # float
print(type("Riya")) # str
print(type(True)) # bool
print(type([1, 2, 3])) # list
print(type(None)) # NoneType

Output

<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>
<class 'list'>
<class 'NoneType'>

The word class in the output just means “type” here. So <class 'int'> is Python telling you the value is an integer. The type() tool is your friend whenever a program behaves in a way you did not expect. Print the type, and you often spot the problem right away.

Tip

When a number arrives as text, like "25" from user input, math will not work the way you expect. A quick print(type(my_value)) shows you it is a str, not an int. So you know you need to convert it first. We cover converting types in a later lesson.

🔄 Mutable vs Immutable

This sounds like a big word, but the idea is simple. Some values can be changed in place after you make them. Some cannot.

  • Mutable means changeable. You can edit the value itself, and it stays the same object.
  • Immutable means fixed. Once made, the value cannot change. To get a different value, you make a brand new one.

This snippet shows a list being changed in place, which works fine.

colors = ["red", "green"]
colors.append("blue") # change the list in place
print(colors)

Output

['red', 'green', 'blue']

The list is mutable, so append adds “blue” to the same list. Now compare that with a tuple, which is immutable.

point = (3, 4)
# point[0] = 99 # ❌ Avoid: this raises a TypeError, tuples cannot change
new_point = (99, 4) # ✅ Good: make a new tuple instead
print(new_point)

Output

(99, 4)

Here is the quick split of the common types.

Mutable (can change) Immutable (cannot change)
list, set, dict int, float, str, bool, tuple, NoneType

Why does this matter? When you share the same mutable value across your program and then change it, every place that uses it sees the change. That can be exactly what you want. It can also surprise you. Knowing which types are mutable helps you avoid those surprises. Each type’s own lesson goes deeper into this.

⚠️ Common Mistakes

A few slip-ups catch almost everyone at the start.

  • Forgetting quotes around text. name = Riya makes Python look for a variable called Riya and crash. Text always needs quotes: name = "Riya".
  • Writing true or false in lowercase. Python only accepts True and False with a capital first letter.
# ❌ Avoid: lowercase boolean, Python does not know what this is
is_open = true
# ✅ Good: capital first letter
is_open = True
  • Mixing up a string number and a real number. "25" with quotes is text. 25 without quotes is a number. You cannot do math on the text version until you convert it.
  • Trying to change a tuple or a string in place. They are immutable, so you build a new one instead of editing the old one.

✅ Best Practices

  • Reach for type() whenever a value behaves oddly. It is the fastest way to see what you are actually holding.
  • Pick the type that fits the job. Use a list when order and editing matter. Use a set when you need unique items. Use a dict when each item needs a label.
  • Use None on purpose to mean “no value yet”. Not zero, and not an empty string.
  • Name variables for what they hold, like is_member for a boolean or colors for a list. The name should hint at the type.

🧩 What You’ve Learned

✅ A data type is the kind of value something is, and each type comes with its own set of things you can do.

✅ The everyday basics are int (whole numbers), float (decimals), str (text), and bool (True/False).

✅ The collections are list, tuple, set, and dict, for holding many things at once.

None (type NoneType) means “no value yet”, on purpose.

type(value) tells you the type of any value, which is great for spotting bugs.

✅ Mutable types like list, set, and dict can change in place. Immutable types like int, str, and tuple cannot.

Check Your Knowledge

Test what you learned. Pick an answer for each question, then click Check.

  1. 1

    Which type would Python give the value 9.99?

    Why: A number written with a decimal point is a float.

  2. 2

    What does type("Riya") report?

    Why: Anything inside quotes is a string, so type() reports <class 'str'>.

  3. 3

    Which group of types is mutable, meaning you can change them in place?

    Why: list, set, and dict are mutable; numbers, strings, and tuples are immutable.

  4. 4

    What does None represent in Python?

    Why: None is a special value meaning 'no value yet', and it is not zero or an empty string.

🚀 What’s Next?

Now that you know the kinds of values Python works with, the next step is doing math with them. Let’s start with the operators that add, subtract, multiply, and divide.

Arithmetic Operators

Share & Connect