A vibrant insect sits on lush green tea leaves in the heart of Yunnan, China.

Table of Contents

 

Alright, syntax rules are in place. Now let’s talk about something you’ll use in literally every single Python program you ever write — variables and data types.

If programming is about giving instructions to a machine, then variables are how you give the machine something to remember. And data types tell Python what kind of thing it’s remembering.

What is a Variable?

A variable is a container. A box with a label on it. You put something inside, give it a name, and from that point on — whenever you use that name, Python knows exactly what you’re referring to. 

Creating a variable in Python is as simple as this:

				
					name = "Aryan"
				
			

That’s it. No special keyword needed, no declaring types upfront. Just a name, an equals sign, and a value. Python figures out the rest on its own.

The = here is not checking equality — it’s assigning a value. You’re telling Python: create a box called name, and put “Aryan” inside it.

Naming Rules for Variables

Python gives you a lot of freedom with variable names, but there are a few rules:

  • Must start with a letter or an underscore — not a number
  • Can contain letters, numbers, and underscores
  • Cannot contain spaces — use underscores instead
  • Cannot be a Python keyword (no calling your variable if or for)
				
					my_name = "Aryan"    # valid
name1 = "Aryan"      # valid
1name = "Aryan"      # invalid — cannot start with a number
my name = "Aryan"    # invalid — no spaces allowed

				
			

A good habit: make your variable names descriptive. age is better than a. user_name is better than un. Future you will appreciate it.

What are Data Types?

Not all data is the same. A person’s name is different from their age, which is different from their account balance, which is different from whether they’re logged in or not. Python handles this through data types.

Let’s go through the main ones:

1. Integer (int)

Whole numbers. No decimals.

				
					age = 25
year = 2024

				
			

2. Float (float)

Numbers with decimal points.

				
					price = 199.99
temperature = 36.6

				
			

3. String (str)

Text. Anything inside quotes — single or double — is a string.

				
					name = "Aryan"
city = 'Mumbai'

				
			

Even a number inside quotes becomes a string:

				
					phone = "9876543210"   # this is a string, not an integer
				
			

4. Boolean (bool)

Only two possible values — True or False. Capital T and F — always. Python is case sensitive, remember?

				
					is_logged_in = True
has_paid = False

				
			

Booleans are used constantly in logic — when you want Python to make decisions based on whether something is true or false. We’ll see a lot more of them in upcoming posts.

5. None

And then there’s a special one — None. This is Python’s way of saying ‘nothing’. No value. Empty. It’s not zero, it’s not an empty string — it’s the intentional absence of a value.

				
					result = None
				
			

When is this useful? Imagine you’re writing a program that looks up a user’s score. If the user hasn’t played yet, their score isn’t 0 — it’s nothing. That’s where None comes in. It’s a meaningful placeholder that says: this exists, but has no value yet. 

You’ll also see None returned by functions that don’t explicitly return anything — but that’s a topic for another day.

Checking the Type of a Variable

Python has a handy built-in function called type() that tells you what data type a variable is:

				
					name = "Aryan"
age = 25
print(type(name))   # <class 'str'>
print(type(age))    # <class 'int'>

				
			

This is incredibly useful when debugging — if your program is behaving unexpectedly, sometimes it’s because a variable is a different type than you assumed.

Quick Recap

  • A variable is a named container that stores a value
  • Use descriptive names — follow the naming rules
  • int — whole numbers, float — decimals, str — text, bool — True/False
  • None means ‘no value’ — not zero, not empty, just nothing
  • Use type() to check what data type a variable is

Variables and data types are the building blocks of every program. Everything you do in Python — calculations, decisions, storing user info — involves these. Next, we go deeper into strings because they’re everywhere and they deserve their own spotlight.