Python Data Types: A Beginner-Friendly Guide
Python is one of the most popular programming languages because it is simple to learn, easy to read, and powerful enough for everything from web development to data science and artificial intelligence.
One of the first concepts every Python beginner should understand is data types.
In this article, we’ll learn what data types are, the most commonly used data types in Python, and how to work with them using simple examples.
What Are Data Types in Python?
A data type tells Python what kind of value a variable contains.
For example:
name = "Rahul"
age = 25
salary = 45000.50
is_employee = TrueHere:
nameis a stringageis an integersalaryis a floatis_employeeis a boolean
Python automatically determines the data type when you assign a value to a variable.
You can check the type of a value using the type() function.
name = "Rahul"
print(type(name))Output:
<class 'str'>Main Data Types in Python
Python has several built-in data types. The most commonly used ones are:
- String (
str) - Integer (
int) - Float (
float) - Complex (
complex) - Boolean (
bool) - List (
list) - Tuple (
tuple) - Set (
set) - Dictionary (
dict) - None (
NoneType)
Let’s understand each one.
1. String (str)
A string is a sequence of characters.
Strings are used to store text such as names, addresses, messages, and sentences.
name = "Rahul"
city = "Pune"
message = "Welcome to Python"You can use either single quotes or double quotes.
name = 'Rahul'
city = "Pune"You can also perform operations on strings.
first_name = "Rahul"
last_name = "Patil"full_name = first_name + " " + last_nameprint(full_name)
Output:
Rahul PatilYou can find the length of a string using len().
name = "Python"print(len(name))Output:
6Useful String Methods
text = "python programming"print(text.upper())
print(text.lower())
print(text.capitalize())Output:
PYTHON PROGRAMMING
python programming
Python programming2. Integer (int)
An integer is a whole number without a decimal point.
Examples:
age = 25
marks = 90
year = 2026
temperature = -5You can perform mathematical operations with integers.
a = 10
b = 5print(a + b)
print(a - b)
print(a * b)
print(a / b)Output:
15
5
50
2.0Note that / produces a float in Python, even when both numbers are integers.
For example:
print(10 / 2)Output:
5.03. Float (float)
A float represents a number containing a decimal point.
Examples:
price = 99.99
height = 5.8
percentage = 87.5You can perform mathematical operations with floats.
price = 100.50
discount = 10.25final_price = price - discountprint(final_price)
Output:
90.254. Complex (complex)
Python also supports complex numbers.
A complex number has a real part and an imaginary part.
Example:
number = 3 + 4jprint(number)Output:
(3+4j)You can access the real and imaginary parts separately.
number = 3 + 4jprint(number.real)
print(number.imag)Output:
3.0
4.0Complex numbers are mainly used in areas such as mathematics, engineering, and scientific computing.
5. Boolean (bool)
A Boolean data type has only two possible values:
TrueFalse
Booleans are commonly used in conditions and decision-making.
is_logged_in = True
is_admin = Falseprint(is_logged_in)
print(is_admin)Output:
True
FalseFor example:
age = 20print(age >= 18)Output:
TrueThis is because the condition age >= 18 is true.
6. List (list)
A list is used to store multiple values in a single variable.
Lists are:
- Ordered
- Mutable
- Allow duplicate values
Example:
fruits = ["apple", "banana", "orange"]print(fruits)Output:
['apple', 'banana', 'orange']You can access individual elements using their index.
fruits = ["apple", "banana", "orange"]print(fruits[0])
print(fruits[1])Output:
apple
bananaPython uses zero-based indexing, which means the first element has index 0.
Lists Are Mutable
You can change elements in a list.
fruits = ["apple", "banana", "orange"]fruits[1] = "mango"print(fruits)
Output:
['apple', 'mango', 'orange']You can also add new elements.
fruits.append("grapes")print(fruits)7. Tuple (tuple)
A tuple is similar to a list, but it is immutable.
Get Warkadkrishna’s stories in your inbox
Join Medium for free to get updates from this writer.
This means that once a tuple is created, its elements cannot be changed.
Example:
colors = ("red", "green", "blue")print(colors)You can access tuple elements using indexes.
print(colors[0])Output:
redBut this will cause an error:
colors[0] = "yellow"Tuples are useful when you want to store data that should not be modified.
8. Set (set)
A set is an unordered collection of unique values.
Sets automatically remove duplicate values.
Example:
numbers = {1, 2, 3, 4, 4, 5}print(numbers)Output:
{1, 2, 3, 4, 5}Notice that the duplicate 4 appears only once.
You can add values to a set using add().
numbers = {1, 2, 3}numbers.add(4)print(numbers)
Sets are particularly useful when you need to work with unique values or perform mathematical set operations.
9. Dictionary (dict)
A dictionary stores data in key-value pairs.
Dictionaries are extremely useful in Python and are commonly used when working with structured data.
Example:
student = {
"name": "Rahul",
"age": 21,
"course": "Python"
}print(student)You can access a value using its key.
print(student["name"])Output:
RahulYou can add or update values.
student["age"] = 22
student["city"] = "Pune"print(student)A dictionary is useful when you want to represent information about an object.
For example:
employee = {
"name": "Amit",
"department": "IT",
"salary": 50000
}Here, each key describes the corresponding value.
10. None (NoneType)
None represents the absence of a value.
Example:
result = Noneprint(result)Output:
NoneYou will often see None when a variable does not currently have a value or when a function doesn't explicitly return a value.
For example:
def hello():
print("Hello")result = hello()print(result)
The function prints Hello, but it doesn't return anything, so result contains None.
Checking the Data Type
Python provides the type() function to determine the data type of a value.
name = "Rahul"
age = 25
salary = 50000.50
skills = ["Python", "SQL"]print(type(name))
print(type(age))
print(type(salary))
print(type(skills))Output:
<class 'str'>
<class 'int'>
<class 'float'>
<class 'list'>Type Conversion in Python
Sometimes you need to convert one data type into another.
This is called type conversion or type casting.
For example, you can convert a string into an integer using int().
age = "25"age = int(age)print(age)
print(type(age))
Output:
25
<class 'int'>Common Type Conversion Functions
FunctionConverts To int()Integer float()Float str()String list()List tuple()Tuple set()Set bool()Boolean
Example:
number = 10print(float(number))
print(str(number))Output:
10.0
10Mutable vs Immutable Data Types
One important concept in Python is the difference between mutable and immutable objects.
Mutable
Mutable objects can be changed after they are created.
Examples:
- List
- Dictionary
- Set
numbers = [1, 2, 3]numbers.append(4)print(numbers)
The list has been modified.
Immutable
Immutable objects cannot be changed after they are created.
Examples:
- Integer
- Float
- String
- Tuple
- Boolean
For example:
name = "Python"name = name + " Programming"print(name)
Technically, Python creates a new string rather than modifying the original string.
Python Data Types Cheat Sheet
Here is a quick summary:
Data TypeExampleMutable? int10No float10.5No complex2 + 3jNo str"Hello"No boolTrueNo list[1, 2, 3]Yes tuple(1, 2, 3)No set{1, 2, 3}Yes dict{"name": "Rahul"}Yes NoneTypeNoneNo
Conclusion
Understanding data types is one of the most important steps when learning Python.
The most commonly used data types are:
- String for text
- Integer for whole numbers
- Float for decimal numbers
- Boolean for true/false values
- List for ordered collections
- Tuple for immutable collections
- Set for unique values
- Dictionary for key-value data
- None for representing the absence of a value
Once you understand these data types, concepts such as variables, functions, loops, conditions, and data structures become much easier to learn.
If you’re starting your Python journey, practice creating variables using each data type and experiment with changing, accessing, and converting them.
Happy Coding! 🐍




