Artificial Intelligence: post #1855 — TG.ME

In the previous post, we learned what variables are and how they are used to store data. But what kind of data can a variable store? That's where Data Types come in.

📖 Phase 1: Programming Fundamentals

📌 Topic 5: Data Types

A data type defines the kind of value a variable can store. Different types of data require different operations, so Python classifies them into various data types.

Think of data types as different containers designed for different kinds of items. Just as you wouldn't store water in a paper bag, you shouldn't treat every kind of data the same way in programming.

Why Do We Need Data Types?

Data types help Python:

Store data efficiently.

Perform the correct operations.

Detect invalid operations.

Manage memory effectively.

Basic Data Types in Python

1. Integer ("int")

Integers are whole numbers without decimal points.

Example:

age = 25

marks = 100

print(age)

print(marks)

Output:

25

100

2. Float ("float")

Floats are numbers with decimal points.

Example:

height = 5.8

price = 99.99

print(height)

print(price)

Output:

5.8

99.99

3. String ("str")

A string is a sequence of characters enclosed in single or double quotes.

Example:

name = "Narayan"

city = 'Pune'

print(name)

print(city)

Output:

Narayan

Pune

4. Boolean ("bool")

A Boolean has only two possible values:

"True"

"False"

Example:

is_student = True

has_job = False

print(is_student)

print(has_job)

Output:

True

False

Checking the Data Type

Python provides the type() function to check the data type of a variable.

Example:

age = 21

price = 99.99

name = "Radhe"

print(type(age))

print(type(price))

print(type(name))

Output:

Type Conversion (Preview)

Sometimes you need to convert one data type into another.

Example:

age = "25"

print(int(age))

Output:

25

We'll learn Type Casting in detail in the next topic.

Summary of Common Data Types

Data Type: Integer ("int")

Example: "10"

Data Type: Float ("float")

Example: "3.14"

Data Type: String ("str")

Example: "Hello"

Data Type: Boolean ("bool")

Example: "True"

Key Takeaways

Every value in Python has a data type.

The four basic data types are "int", "float", "str", and "bool".

Python automatically identifies the data type of a value.

Use the type() function to check a variable's data type.

Understanding data types is essential before performing operations on data.

➡️ Double Tap ❤️ For More
❤8🔥2
August 28, 2026 1.2K 3