DEV Community

Gamya
Gamya

Posted on

Understanding Data Types in Python

Python Basics #2 🐍🔥

In the previous article of this Python Basics series, we learned about variables and how Python stores information in memory.

But here’s the thing:

Python doesn’t just store one kind of information.

Sometimes you want to store:

  • Numbers
  • Decimal values
  • Text
  • True/False conditions
  • Collections of data
  • And much more

To handle all of this properly, Python uses something called data types.

Understanding data types is one of the most important steps in becoming comfortable with programming.

And once you truly understand them, writing code becomes way less confusing.

So today, let’s break down Python data types in the simplest way possible — with examples ⚔️


What Is a Data Type?

A data type tells Python what kind of information a variable is storing.

Think of it like character classes in an RPG game.

Different characters have different abilities:

  • A swordsman attacks differently
  • A mage uses magic
  • A healer restores health

Similarly, different data types behave differently in Python.

For example:

power_level = 9000
Enter fullscreen mode Exit fullscreen mode

Python understands this is a number.

But here:

anime_name = "Dragon Ball"
Enter fullscreen mode Exit fullscreen mode

Python understands this is text.

The data type helps Python decide:

  • What operations are allowed
  • How memory should be used
  • How the data should behave

The Main Data Types Beginners Should Know

Today we’ll focus on three important beginner-friendly data types:

  1. Integers (int)
  2. Floating-point numbers (float)
  3. Boolean values (bool)

These are used everywhere in Python projects.


1. Integers (int) 🔢

An integer is a whole number with no decimal point.

Examples:

episodes = 1000
score = 95
age = 17
Enter fullscreen mode Exit fullscreen mode

All of these are integers.

Integers can be:

  • Positive
  • Negative
  • Zero

Example:

health = 100
enemy_damage = -25
coins = 0
Enter fullscreen mode Exit fullscreen mode

Example 🎌

Imagine you're creating an anime fighting game.

naruto_clones = 2000
Enter fullscreen mode Exit fullscreen mode

Since shadow clones are counted as whole numbers, Python stores this as an integer.

You can perform calculations with integers too.

goku_power = 9000
goku_power = goku_power + 5000

print(goku_power)
Enter fullscreen mode Exit fullscreen mode

Output:

14000
Enter fullscreen mode Exit fullscreen mode

This is how games and apps constantly update values internally.


Why Integers Matter

Integers are commonly used for:

  • Scores
  • Health points
  • Ages
  • Inventory counts
  • Likes on social media
  • Followers
  • Levels in games

Basically, whenever you need whole numbers, integers are usually the answer.


2. Floating-Point Numbers (float) 🌊

A floating-point number (or simply a float) is a number that contains a decimal point.

Examples:

pi = 3.14
rating = 9.8
temperature = 36.5
Enter fullscreen mode Exit fullscreen mode

Unlike integers, floats can store fractional values.


Why Are They Called “Floating-Point”?

The decimal point can “float” to different positions.

For example:

1.5
10.75
999.999
0.0001
Enter fullscreen mode Exit fullscreen mode

The decimal point moves around depending on the number.

That’s why they’re called floating-point numbers.


Example ⚡

Imagine tracking a character’s speed multiplier.

speed_multiplier = 1.75
Enter fullscreen mode Exit fullscreen mode

Or maybe an anime rating app:

demon_slayer_rating = 9.4
Enter fullscreen mode Exit fullscreen mode

Floats are perfect for precise values.


Integer vs Float

Let’s compare them side-by-side.

Integer Float
7 7.0
100 100.5
-3 -3.14

Even though 7 and 7.0 look similar, Python treats them differently.


Checking Data Types in Python

Python provides a very useful function called type().

Example:

power_level = 9000
print(type(power_level))
Enter fullscreen mode Exit fullscreen mode

Output:

<class 'int'>
Enter fullscreen mode Exit fullscreen mode

Now with a float:

rating = 9.7
print(type(rating))
Enter fullscreen mode Exit fullscreen mode

Output:

<class 'float'>
Enter fullscreen mode Exit fullscreen mode

This is extremely useful when debugging programs.


3. Boolean Values (bool) ✅❌

A Boolean variable can only store one of two values:

  • True
  • False

That’s it.

Nothing in between.


Real-Life Example

Think about simple yes/no situations:

  • Is the player alive?
  • Has the mission been completed?
  • Is the villain defeated?
  • Is the account verified?

All of these can be represented using Booleans.


Example 🎭

is_hokage = True
Enter fullscreen mode Exit fullscreen mode

Or:

is_akatsuki_member = False
Enter fullscreen mode Exit fullscreen mode

Booleans are heavily used in decision-making systems.


Why Booleans Are So Important

Booleans power the logic behind applications.

For example:

is_logged_in = True

if is_logged_in:
    print("Welcome back!")
Enter fullscreen mode Exit fullscreen mode

Output:

Welcome back!
Enter fullscreen mode Exit fullscreen mode

This is how apps decide what should happen next.


Important Note About Boolean Values

In Python:

True
False
Enter fullscreen mode Exit fullscreen mode

must start with capital letters.

Wrong:

true
false
Enter fullscreen mode Exit fullscreen mode

Correct:

True
False
Enter fullscreen mode Exit fullscreen mode

Python is case-sensitive.


Combining Data Types Together

Real programs usually use multiple data types together.

Example:

character_name = "Luffy"
bounty = 3000000000
pirate_king_candidate = True
power_multiplier = 1.8
Enter fullscreen mode Exit fullscreen mode

Here we have:

Variable Data Type
character_name String
bounty Integer
pirate_king_candidate Boolean
power_multiplier Float

This is how real applications organize information.


Beginner Mistakes to Avoid 🚨

1. Mixing Up Strings and Numbers

Wrong:

power = "9000" + 1000
Enter fullscreen mode Exit fullscreen mode

This causes an error because "9000" is text, not a number.

Correct:

power = 9000 + 1000
Enter fullscreen mode Exit fullscreen mode

2. Forgetting Decimal Points

rating = 9
Enter fullscreen mode Exit fullscreen mode

This is an integer.

But:

rating = 9.0
Enter fullscreen mode Exit fullscreen mode

This is a float.

Tiny difference.

Big meaning.


3. Using Quotes Around Boolean Values

Wrong:

is_alive = "True"
Enter fullscreen mode Exit fullscreen mode

This becomes text, not a Boolean.

Correct:

is_alive = True
Enter fullscreen mode Exit fullscreen mode

Fun Mini Project 🎮

Let’s create a tiny anime character profile.

character_name = "Gojo"
age = 28
power_level = 9999
cursed_energy_multiplier = 2.5
is_strongest_sorcerer = True

print(character_name)
print(age)
print(power_level)
print(cursed_energy_multiplier)
print(is_strongest_sorcerer)
Enter fullscreen mode Exit fullscreen mode

Output:

Gojo
28
9999
2.5
True
Enter fullscreen mode Exit fullscreen mode

Simple.

But this is already how real applications begin.


Quick Summary 🧠

Data Type Example Purpose
Integer (int) 100 Whole numbers
Float (float) 9.5 Decimal numbers
Boolean (bool) True True/False logic

Final Thoughts

Understanding data types is a huge step in learning Python.

At first, they may seem small and unimportant.

But almost every Python program depends on them.

Games.
Web apps.
AI systems.
Automation scripts.
Data science projects.

Everything uses data types.

So spend time practicing them.

Create weird variables.
Experiment with anime examples.
Break things.
Fix things.

That’s how real learning happens.


Practice Challenge ⚔️

Try creating variables for:

  • Your favorite anime
  • Its rating
  • Number of episodes
  • Whether it is completed or ongoing

Example:

anime_name = "Attack on Titan"
rating = 9.9
episodes = 89
is_completed = True
Enter fullscreen mode Exit fullscreen mode

Then use type() on each variable to see what Python says.


Wrapping Up

This is article #2 in the Python Basics series.

In the next article, we’ll explore:

👉 Strings in Python
👉 String operations
👉 Concatenation
👉 Useful string methods
👉 Common beginner mistakes

Stay tuned 🐍✨

Happy coding!

Top comments (0)