Learn What a Data Type Is in Python: Absolute Beginners Tutorial

Every value you create in Python has a data type. Whether it is a number, a word, a list of items, or the value True, Python assigns a classification to that value behind the scenes. Understanding data types is one of the first things a beginner should learn because it determines what operations you can perform, how Python stores the value in memory, and why certain errors appear when you mix incompatible types together.

This tutorial walks through every major built-in data type in Python, explains what each one is used for, and gives you hands-on interactive exercises to practice. By the end, you will be able to identify the data type of any value, convert between types, and avoid the common mistakes beginners make when working with Python data.

What Is a Data Type and Why Does It Matter

A data type is a classification that tells Python what kind of value a piece of data represents. When you write x = 42, Python does not just store the number 42. It also records that this value is an integer, which means it supports arithmetic operations like addition and multiplication, it can be compared to other numbers, and it takes up a specific amount of space in memory.

Python is a dynamically typed language. This means you do not need to declare a variable's type before using it. When you write name = "Alice", Python sees the quotation marks and automatically assigns the str type. When you write score = 98.5, Python recognizes the decimal point and assigns the float type. The interpreter handles this classification at runtime, not before your program starts.

Note

In statically typed languages like Java or C, you must declare the type of every variable before using it. Python removes that requirement, but the types still exist behind the scenes and still govern what your code can do with each value.

Data types matter because they define the rules. You can add two integers together, but you cannot add an integer to a string without converting one of them first. You can loop through a list, but you cannot loop through a single integer. When Python raises a TypeError, it is telling you that the operation you attempted does not make sense for the data types involved.

The built-in type() function is the fastest way to check what type a value has. Pass any value or variable into type() and it returns the class name that Python assigned to it.

python
age = 25
name = "Alice"
price = 9.99
is_active = True

print(type(age))        # <class 'int'>
print(type(name))       # <class 'str'>
print(type(price))      # <class 'float'>
print(type(is_active))  # <class 'bool'>
Pro Tip

Use isinstance(value, type) when you need to check if a variable is a specific type. It returns True or False and also recognizes subclass relationships, like the fact that bool is a subclass of int.

code builder click a token to place it

Build the correct Python statement to check the data type of a variable called score:

your code will appear here...
type ) score str ( print ( ) class

The Built-in Data Types You Will Use First

Python comes with a rich set of built-in data types, but as a beginner you will spend nearly all of your time working with a core group. These types are available without importing anything -- they are part of the language itself.

Numeric Types: int, float, and complex

Integers (int) are whole numbers with no decimal point. They can be positive, negative, or zero, and Python places no hard limit on how large an integer can be. The only constraint is your computer's available memory.

Floats (float) are numbers with a decimal point. Even if the fractional part is zero, such as 10.0, Python treats it as a float rather than an integer. Floats use 64-bit double-precision representation internally, which means they can occasionally produce small rounding artifacts in arithmetic.

Complex numbers (complex) have a real part and an imaginary part, written as 3+4j. You are unlikely to use complex numbers in everyday programming, but they are built into the language for scientific and mathematical work.

python
whole_number = 42          # int
decimal_number = 3.14      # float
imaginary = 2 + 5j         # complex

print(type(whole_number))   # <class 'int'>
print(type(decimal_number)) # <class 'float'>
print(type(imaginary))      # <class 'complex'>

Text Type: str

Strings (str) are sequences of characters enclosed in single quotes, double quotes, or triple quotes. They are immutable, which means once a string is created, you cannot change individual characters inside it. Any operation that appears to modify a string -- like .upper() or concatenation -- returns a new string object.

python
greeting = "Hello, world"
multiline = """This string
spans multiple lines."""

print(type(greeting))  # <class 'str'>
print(len(greeting))   # 12

Boolean Type: bool

The bool type has only two possible values: True and False. Booleans are used in conditional statements, loop conditions, and logical operations. An important detail for beginners: bool is a subclass of int in Python, which means True has an integer value of 1 and False has an integer value of 0.

Common Mistake

Python booleans are capitalized: True and False. Writing true or false in lowercase will raise a NameError because Python treats them as undefined variable names.

Sequence Types: list, tuple, and range

A list is an ordered, mutable collection that can hold items of any type. Lists are created with square brackets and are one of the data structures you will use the most in Python. A tuple is similar to a list but immutable -- once created, its contents cannot be changed. Tuples are created with parentheses. The range type represents an immutable sequence of numbers and is commonly used in for loops.

Mapping Type: dict

A dict (dictionary) stores data as key-value pairs. Each key must be unique and immutable (strings and numbers are common key types), while values can be any type. Dictionaries are created with curly braces and colons separating keys from values.

Set Types: set and frozenset

A set is an unordered collection of unique elements. Sets automatically remove duplicates and support mathematical operations like union and intersection. A frozenset is the immutable version of a set.

The None Type

None is a special singleton value with the type NoneType. It represents the absence of a value. Functions that do not explicitly return anything return None by default, and it is commonly used as a placeholder for variables that have not yet been assigned meaningful data.

Example
x = 42
Mutable
No
Use case
Counting, indexing, arithmetic on whole numbers
Example
price = 9.99
Mutable
No
Use case
Decimal arithmetic, measurements, scientific calculations
Example
name = "Alice"
Mutable
No
Use case
Text processing, labels, user input, file paths
Example
is_valid = True
Mutable
No
Use case
Conditional logic, flags, loop control
Example
items = [1, 2, 3]
Mutable
Yes
Use case
Ordered collections, iteration, stacks, queues
Example
user = {"name": "Alice", "age": 30}
Mutable
Yes
Use case
Key-value lookups, configuration, JSON-like data
Example
result = None
Mutable
No
Use case
Placeholder, default return value, absence of data
spot the bug click the line that contains the bug

This code tries to combine a user's name with their age into a single message. One line has a type-related bug. Find it.

1 name = "Alice"
2 age = 30
3 msg = name + " is " + age
4 print(msg)
The fix: Convert age to a string before concatenating it with other strings. Use str(age) so the corrected line becomes:

msg = name + " is " + str(age)

Python cannot concatenate a string and an integer directly. Attempting to do so raises a TypeError because the + operator does not know how to join two different types.

Mutable vs Immutable Types

One of the distinctions that trips up beginners is the difference between mutable and immutable types. Mutable objects can be changed after they are created. Immutable objects cannot be changed -- any operation that seems to modify them creates a new object instead.

Lists, dictionaries, and sets are mutable. You can append items to a list, add new keys to a dictionary, or remove elements from a set, and the original object in memory is updated in place. Integers, floats, strings, tuples, booleans, and frozensets are immutable. When you write x = x + 1 where x is an integer, Python creates a new integer object with the incremented value and points the variable name x to it. The original integer object remains unchanged.

python
# Mutable example: list
colors = ["red", "green", "blue"]
colors.append("yellow")
print(colors)  # ["red", "green", "blue", "yellow"]

# Immutable example: string
word = "hello"
upper_word = word.upper()
print(word)        # "hello"  (unchanged)
print(upper_word)  # "HELLO"  (new object)

This distinction matters when you pass variables to functions. If you pass a mutable object like a list into a function and the function modifies it, the original list outside the function changes too. Immutable objects do not have this behavior, because any modification inside the function creates a new object rather than altering the original.

"Everything in Python is an object." — Python Documentation

How to Check and Use Data Types in Python

Follow these four steps to confidently identify, verify, and convert data types in your Python programs.

  1. Create a variable with any value

    Assign a value to a variable name. Python will automatically determine the data type based on the value you provide. For example, writing age = 25 creates an integer, and writing name = "Alice" creates a string.

  2. Use type() to check the data type

    Pass your variable to the type() function to see what data type Python assigned. For example, print(type(age)) will output <class 'int'>, confirming the variable holds an integer.

  3. Use isinstance() for type checking

    When you need to verify that a variable is a specific type, use isinstance(). For example, isinstance(age, int) returns True. This approach also recognizes subclasses, making it more reliable than comparing type() results directly.

  4. Convert between types when needed

    Use built-in functions like int(), float(), str(), and list() to convert values between types. For example, int("42") converts a string to an integer, and str(3.14) converts a float to a string. Be aware that invalid conversions like int("hello") will raise a ValueError.

crossword puzzle click a letter, then click a cell

Test your knowledge of Python data types. Pick a letter from the bank below, then click an empty cell in the grid to place it. Click a filled cell to clear it.

letter bank -- click to pick

Python Learning Summary Points

  1. A data type classifies a value and determines what operations Python allows you to perform on it. Python assigns types automatically through dynamic typing.
  2. The core built-in types you will use as a beginner are int, float, str, bool, list, tuple, dict, set, and NoneType.
  3. Use type() to inspect a value's type and isinstance() to test whether a value belongs to a specific type or its subclasses.
  4. Mutable types (list, dict, set) can be changed in place. Immutable types (int, float, str, tuple, bool, frozenset) create new objects when modified.
  5. Type conversion functions like int(), float(), str(), and list() let you explicitly convert between types, but invalid conversions raise exceptions.

Understanding data types gives you a mental model for how Python organizes information. Every variable you create, every function argument you pass, and every return value you receive has a type. As you continue learning Python, recognizing types will help you read error messages, write cleaner code, and reason about how your programs behave.

check your understanding question 1 of 5

Frequently Asked Questions

A data type is a classification that tells Python what kind of value a variable holds and what operations can be performed on it. Python assigns data types automatically when you create a variable.

Use the built-in type() function. For example, type(42) returns <class 'int'> and type("hello") returns <class 'str'>.

Python's main built-in data types include int (integers), float (decimal numbers), str (strings), bool (True or False), list (ordered mutable sequences), tuple (ordered immutable sequences), dict (key-value pairs), set (unordered unique elements), and NoneType (the absence of a value).

A list is mutable, meaning you can add, remove, or change its elements after creation. A tuple is immutable, meaning once created, its contents cannot be changed. Lists use square brackets [] and tuples use parentheses ().

Dynamic typing means Python determines the data type of a variable at runtime based on the value assigned to it, rather than requiring you to declare the type in advance. The same variable can be reassigned to a different type at any point.

Use built-in conversion functions like int(), float(), str(), bool(), and list(). For example, int("42") converts the string "42" to the integer 42, and str(3.14) converts the float 3.14 to the string "3.14".

Mutable types can be changed after creation (lists, dicts, sets). Immutable types cannot be changed once created (int, float, str, tuple, bool, frozenset). When you modify a string or number, Python creates a new object rather than changing the original.

NoneType is the data type of the special value None, which represents the absence of a value. It is commonly used as a default return value for functions that do not explicitly return anything, and as a placeholder for variables that have not yet been assigned meaningful data.

In Python, bool is a subclass of int. This means True has an integer value of 1 and False has an integer value of 0. You can use booleans in arithmetic expressions, where True + True equals 2.

Yes. Because Python uses dynamic typing, you can reassign a variable to a value of a completely different type at any time. For example, x = 10 makes x an int, but x = "hello" immediately changes it to a str.