Data Types
Explore Python's built-in data types — numbers, strings, booleans, and None — and learn the difference between mutable and immutable values.
Introduction
Every value in Python — a number, a word, a true/false answer — belongs to a data type. The data type tells Python what kind of value it is dealing with, and what operations make sense on it. You cannot divide a piece of text by 2 the same way you divide a number by 2, and Python's type system is what keeps track of that difference.
In this lesson, you will tour Python's core built-in data types, learn how dynamic typing lets a variable hold any of them, and get a first look at the important concept of mutability.
- Python's core built-in data types: int, float, complex, str, and bool.
- How dynamic typing lets a value's type drive behavior automatically.
- What the special None type represents.
- The difference between mutable and immutable data.
- A preview of the collection types covered in upcoming lessons.
What is a Data Type?
A data type classifies what kind of value something is — a whole number, a decimal number, text, or a true/false value — and determines which operations are valid on it. Python decides a value's data type automatically based on how you write it.
print(type(10))
print(type(3.5))
print(type("hello"))
print(type(True))<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>Numeric Types
Python has three built-in numeric types, though you will use the first two far more often than the third.
int
Whole numbers with no decimal point, positive or negative — for example 7, -3, or 1000000.
float
Numbers with a decimal point, used for measurements and precise or fractional values — for example 3.14 or -0.5.
complex
Numbers with a real and imaginary part, written like 2 + 3j — rarely used outside scientific and engineering code.
whole_number = 42
decimal_number = 3.14
complex_number = 2 + 3j
print(whole_number, type(whole_number))
print(decimal_number, type(decimal_number))
print(complex_number, type(complex_number))42 <class 'int'>
3.14 <class 'float'>
(2+3j) <class 'complex'>complex numbers store a real part and an imaginary part (marked with j instead of i). You will rarely need them unless you work in fields like signal processing or advanced mathematics.
Text Type: str
Text in Python is represented by the str (string) type — any sequence of characters wrapped in single or double quotes.
city = "Mumbai"
greeting = 'Hello there'
print(city, type(city))
print(greeting, type(greeting))Mumbai <class 'str'>
Hello there <class 'str'>Strings are so important that they get two dedicated lessons later — one for core string behavior and one for string methods and formatting.
Boolean Type: bool
The bool type has exactly two possible values: True and False. Booleans represent yes/no, on/off, or true/false answers, and they are the backbone of every decision your programs make.
is_logged_in = True
has_paid = False
print(is_logged_in, type(is_logged_in))
print(has_paid, type(has_paid))True <class 'bool'>
False <class 'bool'>Note that True and False are capitalized — true and false (lowercase) are not valid in Python and will raise a NameError.
The None Type
Python has a special value called None, which represents "no value" or "nothing here yet." It is its own type, NoneType, and it is commonly used as a placeholder before a variable has a real value, or as a function's result when it has nothing meaningful to return.
result = None
print(result)
print(type(result))None
<class 'NoneType'>None is not the same as 0, False, or an empty string "". It specifically means "the absence of a value," and Python treats it as its own distinct type.
Collection Types Preview
Beyond single values, Python also has data types that hold collections of items. These are important enough to get their own dedicated lessons soon, so here is just a quick preview of what is coming.
list
An ordered, changeable collection of items, written with square brackets, e.g. [1, 2, 3].
tuple
An ordered, unchangeable collection of items, written with parentheses, e.g. (1, 2, 3).
dict
A collection of key-value pairs, written with curly braces, e.g. {"name": "Alex"}.
set
An unordered collection of unique items, also written with curly braces, e.g. {1, 2, 3}.
Checking Types Dynamically
Because Python is dynamically typed, the same variable name can point to completely different types over the life of a program. The type() function always tells you exactly what a variable holds right now.
data = 100
print(type(data))
data = "one hundred"
print(type(data))
data = None
print(type(data))<class 'int'>
<class 'str'>
<class 'NoneType'>Mutable vs Immutable
One of the most important ideas in Python's type system is whether a value can be changed in place after it is created. This property is called mutability, and it affects how values behave when copied or passed around.
Immutable Types
- int, float, complex
- str
- bool
- tuple
Mutable Types
- list
- dict
- set
name = "Alex"
name = name + " Smith"
print(name)Alex SmithThis did not modify the original string in place — it created an entirely new string and reassigned the name variable to point to it. You will see this idea again in much more depth once lists and dictionaries are introduced.
Common Mistakes
- Writing true or false in lowercase instead of True and False.
- Confusing None with 0, False, or an empty string — they are not the same.
- Assuming a variable is locked to one type forever — Python allows reassignment to any type.
- Forgetting that numbers with a decimal point are float, even something like 5.0.
- Mixing up complex numbers' j with the mathematical i — Python uses j.
Best Practices
- Use type() whenever you are unsure what type a value actually is.
- Use None deliberately to represent "no value yet," not as a substitute for 0 or "".
- Choose int for whole numbers and float only when you need decimals.
- Keep mutability in mind — it matters more once you start using lists and dictionaries.
- Do not worry about complex numbers unless your work specifically needs them.
Frequently Asked Questions
What is the difference between int and float?
int stores whole numbers with no decimal point, while float stores numbers that include a decimal point, even if it is .0.
Is None the same as 0 or False?
No. None is its own distinct type, NoneType, and specifically represents the absence of a value, not a numeric or boolean falsy value.
Do I need to use complex numbers as a beginner?
Almost never. complex numbers appear mainly in scientific, engineering, and signal-processing code.
What does mutable mean?
A mutable type can be changed in place after creation, like a list. An immutable type, like a string or tuple, cannot be changed — any change creates a new value instead.
Where will I learn about lists, tuples, sets, and dictionaries in depth?
Each of these collection types has its own dedicated lesson coming up right after strings.
Key Takeaways
- Python's core built-in types include int, float, complex, str, and bool.
- Dynamic typing means a variable's type is determined automatically from its value.
- None is a special type, NoneType, that represents the absence of a value.
- list, tuple, dict, and set are collection types with their own dedicated lessons ahead.
- Immutable types (int, float, str, bool, tuple) cannot be changed in place; mutable types (list, dict, set) can.
Summary
Data types define what kind of value Python is working with and what operations make sense on it. You have now met Python's core scalar types — int, float, complex, str, bool, and None — and previewed the collection types waiting just ahead.
You also learned the important distinction between mutable and immutable types, a concept that will matter a great deal once you start working with lists and dictionaries. Next, you will learn how to convert values between types using type casting.
- You know Python's core built-in data types.
- You understand what None represents.
- You can distinguish mutable types from immutable types.
- You are ready to learn type casting.