TGViewer
Artificial Intelligence Artificial Intelligence @machinelearning_deeplearning · 56.3K subscribers
Post #1855 4.43K
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
  • ❤ 22
  • 👎 1
  • 🔥 1
More from @machinelearning_deeplearning
  1. Sep 22, 2026🚀 Welcome back to our AI Engineer Roadmap! ❤️ In the previous posts, we learned about fun…
  2. Sep 21, 2026🚀 Welcome back to our AI Engineer Roadmap! ❤️ In the previous post, we explored functions…
  3. Sep 20, 2026In the previous post, we learned how conditional statements allow Python programs to make…
  4. Sep 19, 2026In the previous post, we explored Python operators and even tested ourselves with some tri…
  5. Sep 18, 2026In the previous post, we learned how to convert one data type into another using Type Cast…
  6. Sep 17, 2026In the previous post, we learned how to take input from users and display output. One impo…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →