DEV Community

Gamya
Gamya

Posted on

Understanding Variables

If you're starting your Python journey, one of the very first things you'll encounter is variables.

And honestly?

Variables are everywhere in programming.

Whether you're building web apps, automating boring tasks, analyzing data, or creating games, you'll constantly use variables to store and manage information.

In this article, we'll break down variables in the simplest way possible—with some anime-inspired examples to make things fun and memorable.

So grab your ramen 🍜, and let's begin.


What Exactly Is a Variable?

A variable is simply a named storage location in a computer’s memory.

Sounds technical?

Let’s simplify it.

Imagine you’re watching an anime where every character carries a special scroll or inventory box.

Each box has:

  • A label (the variable name)
  • Something stored inside it (the value)

For example:

power_level = 9000
Enter fullscreen mode Exit fullscreen mode

Here:

  • power_level → variable name
  • 9000 → value stored inside it

Python remembers this value so your program can use it later.

Think of it like this:

Variable Stored Value
hero_name "Naruto"
chakra_level 500
is_hokage False

Creating Variables in Python

Creating a variable is super easy in Python.

You simply assign a value using the = operator.

anime_name = "One Piece"
episodes = 1000
rating = 9.8
Enter fullscreen mode Exit fullscreen mode

This process is called assignment.

You are basically telling Python:

“Hey Python, store this information for me.”


Variables Can Change (And That’s Their Superpower)

Variables are called variables because their values can change.

chakra = 50
chakra = 100
Enter fullscreen mode Exit fullscreen mode

Initially, chakra was 50.

Later, we changed it to 100.

Python always keeps the latest assigned value.


Example 🎌

Imagine a character leveling up during battle.

goku_power = 5000

# After training
goku_power = 9000

# After Ultra Instinct
goku_power = 1000000
Enter fullscreen mode Exit fullscreen mode

The variable stays the same.

Only the value changes.

That’s exactly how variables behave.


Why Variables Matter So Much

Without variables, programming would be chaos.

Variables help us:

  • Store user information
  • Track scores in games
  • Save data from APIs
  • Count items
  • Build logic
  • Make applications dynamic

For example:

player_health = 100
enemy_damage = 30

player_health = player_health - enemy_damage

print(player_health)
Enter fullscreen mode Exit fullscreen mode

Output:

70
Enter fullscreen mode Exit fullscreen mode

This is how games calculate damage internally.

Pretty cool, right?


Rules for Naming Variables in Python

Python has some rules for variable names.

Let’s go through them one by one.


1. Variable Names Cannot Start With Numbers ❌

Wrong:

1piece = "Luffy"
Enter fullscreen mode Exit fullscreen mode

Correct:

one_piece = "Luffy"
piece1 = "Luffy"
Enter fullscreen mode Exit fullscreen mode

2. Spaces Are Not Allowed ❌

Wrong:

anime hero = "Zoro"
Enter fullscreen mode Exit fullscreen mode

Correct:

anime_hero = "Zoro"
Enter fullscreen mode Exit fullscreen mode

3. Special Characters Are Not Allowed ❌

Wrong:

power-level = 9000
hero$name = "Naruto"
Enter fullscreen mode Exit fullscreen mode

Correct:

power_level = 9000
hero_name = "Naruto"
Enter fullscreen mode Exit fullscreen mode

You can only use:

  • Letters
  • Numbers
  • Underscores

Good Variable Names vs Bad Variable Names

Bad:

x = 100
Enter fullscreen mode Exit fullscreen mode

Good:

player_health = 100
Enter fullscreen mode Exit fullscreen mode

Why?

Because descriptive names make your code easier to read.

Imagine working on a project after 6 months.

You’ll thank your past self for writing meaningful variable names.


Snake Case vs Camel Case 🐍🐫

There are two popular naming styles.

Snake Case (Most Common in Python)

Words are separated using underscores.

player_power_level = 9000
Enter fullscreen mode Exit fullscreen mode

Python developers mostly use this style.


Camel Case

Each new word starts with a capital letter.

playerPowerLevel = 9000
Enter fullscreen mode Exit fullscreen mode

Camel case is common in languages like JavaScript and Java.

But in Python?

Snake case wins almost every time.


Variables Can Store Different Types of Data

Variables are not limited to numbers.

Python can store many types of information.

Strings (Text)

anime = "Attack on Titan"
Enter fullscreen mode Exit fullscreen mode

Integers (Whole Numbers)

titans_defeated = 50
Enter fullscreen mode Exit fullscreen mode

Floats (Decimal Numbers)

rating = 9.7
Enter fullscreen mode Exit fullscreen mode

Booleans (True/False)

is_alive = True
Enter fullscreen mode Exit fullscreen mode

Fun Mini Example 🎮

Let’s create a tiny anime character system.

character_name = "Ichigo"
health = 100
bankai_unlocked = True

print(character_name)
print(health)
print(bankai_unlocked)
Enter fullscreen mode Exit fullscreen mode

Output:

Ichigo
100
True
Enter fullscreen mode Exit fullscreen mode

Simple.

But this tiny concept is the foundation of huge applications.

Even massive apps like Netflix, Instagram, and Spotify rely heavily on variables behind the scenes.


Beginner Mistakes to Avoid 🚨

1. Forgetting Quotes Around Text

Wrong:

anime = Naruto
Enter fullscreen mode Exit fullscreen mode

Correct:

anime = "Naruto"
Enter fullscreen mode Exit fullscreen mode

2. Using Confusing Names

Avoid:

a = 10
b = 20
Enter fullscreen mode Exit fullscreen mode

Prefer:

player_score = 10
enemy_score = 20
Enter fullscreen mode Exit fullscreen mode

3. Accidentally Overwriting Variables

coins = 100
coins = 0
Enter fullscreen mode Exit fullscreen mode

Be careful when reassigning values.

Python only remembers the latest one.


Final Thoughts

Variables are one of the most important concepts in programming.

Mastering them early makes everything else easier later:

  • Conditions
  • Loops
  • Functions
  • APIs
  • Data structures
  • Web development
  • Automation
  • AI projects

Everything builds on top of variables.

So don’t rush this topic.

Practice creating variables daily.

Experiment with funny examples.

Build tiny anime-themed scripts.

And most importantly—enjoy the learning process.


Quick Practice Challenge ⚔️

Try creating variables for:

  • Your favorite anime character
  • Their power level
  • Their age
  • Whether they are a hero or villain

Example:

character_name = "Levi"
power_level = 9500
age = 34
is_hero = True
Enter fullscreen mode Exit fullscreen mode

Try printing them using print().


Wrapping Up

This is the first article in my Python Basics series.

In the next article, we’ll explore:

👉 Data Types in Python
👉 How Python understands different kinds of information
👉 Type conversion and common beginner mistakes

Stay tuned. 🚀

And if this article helped you even a little, feel free to drop a reaction or share it with another beginner developer.

Happy coding 🐍✨

Top comments (0)