Chapter 05 of 11

Python Data Types

Every value in a Python program has a data type. A data type tells Python what kind of value we're working with and what operations can be performed on it.

For example, 25 is a number, while "John" is text. Python treats these values differently.

Let's look at the most important data types you'll use in Python.

What is a Data Type?

A data type defines the kind of value stored in a variable.

For example:

name = "John"
age = 20
price = 99.99

Here:

  • "John"str (string)

  • 20int (integer)

  • 99.99float (floating-point number)

Python automatically determines the data type when you assign a value.

Common Python Data Types

Here are the main built-in data types you'll encounter:

Data Type

Example

Used For

str

"Hello"

Text

int

25

Whole numbers

float

10.5

Decimal numbers

complex

2 + 3j

Complex numbers

bool

True

True/false values

list

[10, 20, 30]

Ordered collection

tuple

(10, 20, 30)

Ordered, immutable collection

set

{10, 20, 30}

Unique values

dict

{"name": "John"}

Key-value data

NoneType

None

No value

Let's understand the important ones.

1. String (str)

A string is used to store text.

name = "John"
message = "Hello Python"

Strings can be written using single or double quotes:

name = 'John'
language = "Python"

Both are valid.

2. Integer (int)

An integer is a whole number without a decimal point.

age = 20
score = 95
temperature = -5

Positive, negative, and zero are all integers.

3. Float (float)

A float represents a number containing a decimal point.

price = 99.99
height = 5.8

Python uses the float type for these values.

4. Complex (complex)

Python also supports complex numbers.

number = 2 + 3j

Here, 2 is the real part and 3j is the imaginary part.

You won't usually need complex numbers when learning basic Python, but Python supports them when they're required for mathematical or scientific applications.

5. Boolean (bool)

A Boolean value can only be:

True
False

For example:

is_logged_in = True
is_admin = False

Booleans are commonly used with conditions.

is_logged_in = True

if is_logged_in:
    print("Welcome!")

6. List (list)

A list is used to store multiple values in a single variable.

fruits = ["Apple", "Banana", "Mango"]

Lists are ordered and can be modified.

fruits = ["Apple", "Banana", "Mango"]

fruits[0] = "Orange"

print(fruits)

Output:

['Orange', 'Banana', 'Mango']

We'll learn lists and their methods in detail later.

7. Tuple (tuple)

A tuple is similar to a list, but it cannot be changed after it is created.

coordinates = (10, 20)

Tuples are useful when you want to keep a collection of values unchanged.

8. Set (set)

A set stores unique values.

numbers = {10, 20, 30, 20}

print(numbers)

The duplicate 20 is removed.

{10, 20, 30}

Sets are useful when you don't want duplicate values.

9. Dictionary (dict)

A dictionary stores data in key-value pairs.

student = {
    "name": "John",
    "age": 20,
    "marks": 85
}

Here:

"name"  → "John"
"age"   → 20
"marks" → 85

You can access a value using its key:

print(student["name"])

Output:

John

Dictionaries are extremely useful when working with structured data.

10. None (NoneType)

Python has a special value called None, which represents the absence of a value.

result = None

It basically means that the variable currently has no meaningful value.

Checking the Data Type

You can use the type() function to check the type of a value.

name = "John"
age = 20
price = 99.99

print(type(name))
print(type(age))
print(type(price))

Output:

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

Python is Dynamically Typed

One interesting thing about Python is that you don't have to explicitly declare a variable's type.

For example:

value = 10

Python knows that value is an integer.

Later, you can assign a string to the same variable:

value = "Hello"

Now value contains a string.

This is called dynamic typing.

Final Example

Let's use several data types together:

name = "John"
age = 20
height = 5.8
is_student = True
subjects = ["Python", "Math", "Science"]

print(name)
print(age)
print(height)
print(is_student)
print(subjects)

Each variable stores a different type of data.

Understanding data types is important because almost everything you do in Python—calculations, conditions, loops, functions, and data processing—depends on knowing what kind of data you're working with.