Sitemap
Warkadkrishna

Warkadkrishna

Python Data Types: A Beginner-Friendly Guide

5 min readOct 6, 2026

--

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 = True

Here:

  • name is a string
  • age is an integer
  • salary is a float
  • is_employee is 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:

  1. String (str)
  2. Integer (int)
  3. Float (float)
  4. Complex (complex)
  5. Boolean (bool)
  6. List (list)
  7. Tuple (tuple)
  8. Set (set)
  9. Dictionary (dict)
  10. 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 Patil

You can find the length of a string using len().

name = "Python"
print(len(name))

Output:

6

Useful String Methods

text = "python programming"
print(text.upper())
print(text.lower())
print(text.capitalize())

Output:

PYTHON PROGRAMMING
python programming
Python programming

2. Integer (int)

An integer is a whole number without a decimal point.

Examples:

age = 25
marks = 90
year = 2026
temperature = -5

You can perform mathematical operations with integers.

a = 10
b = 5
print(a + b)
print(a - b)
print(a * b)
print(a / b)

Output:

15
5
50
2.0

Note that / produces a float in Python, even when both numbers are integers.

For example:

print(10 / 2)

Output:

5.0

3. Float (float)

A float represents a number containing a decimal point.

Examples:

price = 99.99
height = 5.8
percentage = 87.5

You can perform mathematical operations with floats.

price = 100.50
discount = 10.25
final_price = price - discountprint(final_price)

Output:

90.25

4. Complex (complex)

Python also supports complex numbers.

A complex number has a real part and an imaginary part.

Example:

number = 3 + 4j
print(number)

Output:

(3+4j)

You can access the real and imaginary parts separately.

number = 3 + 4j
print(number.real)
print(number.imag)

Output:

3.0
4.0

Complex 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:

  • True
  • False

Booleans are commonly used in conditions and decision-making.

is_logged_in = True
is_admin = False
print(is_logged_in)
print(is_admin)

Output:

True
False

For example:

age = 20
print(age >= 18)

Output:

True

This 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
banana

Python 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:

red

But 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:

Rahul

You 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 = None
print(result)

Output:

None

You 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 = 10
print(float(number))
print(str(number))

Output:

10.0
10

Mutable 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! 🐍

--

--