What Is a Data Type in Python?

A data type in Python tells Python what kind of value you are working with.

For example, a value might be:

  • text
  • a whole number
  • a decimal number
  • True or False

Data types matter because they affect what you can do with a value. Python uses them to decide how values are stored and how operations should behave.

What a data type means

A data type describes the kind of value you are using.

Here are a few simple examples:

  • Text uses the string type
  • Whole numbers use the integer type
  • Decimal numbers use the float type
  • True and False use the boolean type

Different data types support different operations.

For example:

  • You can add numbers with +
  • You can join strings with +
  • Some operations work for one type but not another
print(2 + 3)
print("hello" + " world")

Output:

5
hello world

Even though both lines use +, Python handles them differently because the data types are different.

Simple examples of data types

Some common built-in Python data types are:

  • String: text like "hello"
  • Integer: whole number like 5
  • Float: decimal number like 3.14
  • Boolean: True or False
  • List: a collection like [1, 2, 3]
  • Dictionary: key-value data like {"name": "Sam"}

Example:

message = "hello"
count = 5
price = 3.14
is_ready = True
numbers = [1, 2, 3]
user = {"name": "Sam"}

Each value has its own type.

If you want a broader introduction, see Python data types overview.

Why data types matter

Data types matter because they affect what your code can do.

For example:

  • Numbers can be added
  • Strings behave like text
  • Some combinations of types cause errors
  • Choosing the right type makes your code easier to work with

This works:

print(10 + 5)

But this causes a problem:

print("10" + 5)

Python raises an error because "10" is a string and 5 is an integer. These types do not work together in that operation.

If you want to understand this more clearly, see TypeError vs ValueError in Python explained.

How Python knows a value's type

Python usually figures out the type from the value itself.

Common examples:

  • Quotes usually mean a string: "hello"
  • A whole number is usually an int: 5
  • A decimal number is usually a float: 3.14
  • True and False are booleans

You can check a value's type with type().

print(type("hello"))
print(type(5))
print(type(3.14))
print(type(True))

Output:

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

If you want to learn more about this function, see Python type() function explained.

Variables and data types

A variable stores a value.

The value inside the variable has a data type.

In Python, you do not need to declare the type first. Python works it out when you assign the value.

x = 5
print(type(x))

x = "hello"
print(type(x))

Output:

<class 'int'>
<class 'str'>

This means the same variable can later store a different type of value.

If you are still learning variables, see what is a variable in Python.

Common beginner confusion

These are very common mistakes when learning data types:

  • "5" is a string, not an integer
  • 5 and 5.0 are different types
  • True is a boolean, not a string
  • A list and a tuple are different types, even if they look similar

Example:

print(type("5"))
print(type(5))
print(type(5.0))
print(type(True))
print(type([1, 2, 3]))
print(type((1, 2, 3)))

Output:

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

When to learn more next

Once you understand the basic idea of data types, the next useful step is to learn specific types in more detail.

Good next topics are:

Type conversion is especially useful because it lets you change one type into another when needed.

Common mistakes

Beginners often run into problems like these:

  • Treating a string like a number
  • Assuming all numbers are the same type
  • Confusing a variable name with the value's type
  • Mixing incompatible data types in one operation

These commands can help you check what is happening:

value = "5"

print(type(value))
print(isinstance(value, int))
print(isinstance(value, str))

Output:

<class 'str'>
False
True

Useful checks:

  • type(value)
  • print(type(value))
  • isinstance(value, int)
  • isinstance(value, str)

FAQ

What is a data type in simple words?

It is the kind of value you are working with, such as text, a number, or True/False.

Does Python require me to declare data types?

No. Python figures out the type from the value you assign.

Is "10" the same as 10 in Python?

No. "10" is a string and 10 is an integer.

How do I check a data type in Python?

Use the type() function, such as type(5) or type("hello").

Why do data types matter?

They affect what operations are allowed and help prevent errors in your code.

See also