Python Variables, Data Types, and Basic Operations

So you’ve installed Python, got your first “Hello, world!” printed on the screen, and now you’re wondering — what next?

This next step is all about working with information. 

Think of it like learning how to use boxes and labels to hold things. In this post, we’ll take a look at three key areas:

  • How Python stores values using variables
  • The different types of data it understands
  • Simple ways to work with those values

Let’s dive in and keep things light and practical.

📦 What Are Variables?

In everyday life, we give names to things so we can refer to them later. Python does something similar. 

It allows you to name a piece of information and store it. These names are called variables.

Example:

name = "Arif"
age = 25
height = 5.9

Here’s what’s happening:

name is a label for the text “Arif”

age is holding the number 25

height is keeping track of 5.9, which is a decimal

No need to declare the type of data first — Python figures it out on its own. 

You just write the variable name, add an =, and give it a value.

Rules for Naming Variables

Before you go wild with names, here are some simple rules to remember:

  • Names can only contain letters, numbers, and underscores
  • They can’t start with a number
  • They shouldn’t use spaces (use underscores instead)
  • Names like print, if, or for are already used by Python — avoid those

Here are some example of valid names:

user_name
number1
total_income

Examples of Invalid names:

1name   # starts with a number
total income  # has a space
print    # reserved word

Stick with names that make sense — it helps you and others understand your code later.

Python’s Basic Data Types

Python can understand many types of information. Here are the most common ones you’ll use in the beginning:

1. Text (String) 

Text/strings are used for words or characters.

greeting = "Hello"

You’ll often see strings wrapped in double or single quotes.

2. Whole Numbers (Integer)

year = 2025

No decimal points, just clean whole numbers.

3. Decimal Numbers (Float)

price = 19.99

Useful for money, percentages, or measurements.

4. True or False (Boolean)

is_active = True
is_logged_in = False

These are perfect for checking conditions.

5. Empty or None

result = None

This means the value exists, but it hasn’t been set yet.

Checking the Type of a Variable

Want to see what type of data a variable has? You can use type():

a = "Hello"
print(type(a))  # Output: <class 'str'>

This helps when your code isn’t behaving, and you want to confirm what kind of value you’re working with.

Basic Math Operations in Python

Python handles numbers like a calculator. Here are the main operations:

OperationSymbolExampleResult
Add+3 + 25
Subtract7 – 43
Multiply*5 * 210
Divide/10 / 25.0
Floor Divide//7 // 23
Modulo%7 % 21
Power**2 ** 38

Here’s a short snippet:

a = 10
b = 3
print(a + b) # 13
print(a // b)   # 3 (whole number result)
print(a % b) # 1 (remainder)

Mixing Data and Getting Errors

Let’s say you try this:

age = 25
text = "My age is " + age

Python will complain. 

Why? Because you’re trying to add text and a number, which it doesn’t understand.

To fix it:

text = "My age is " + str(age)

Use str() to turn a number into text.

Comments in Python

Comments help you write notes in your code. 

Python skips over them when it runs your file.

# This is a comment
name = "Sami"  # This sets the name

They’re useful when you want to explain why you’re doing something, not just what you’re doing.

Playing with Variables

Try this short example:

first_name = "Rina"
last_name = "Khan"
full_name = first_name + " " + last_name

print("Full name is:", full_name)

Output:

Full name is: Rina Khan

You’re combining text (called concatenation) and printing the result.

A Quick Practice

Try this small task to check what you’ve learned:

Create a script that:

  1. Stores your name, birth year, and favorite number
  1. Calculates your age
  1. Prints all of it in a nice sentence
name = "Tariq"
birth_year = 1995
fav_number = 7

current_year = 2025
age = current_year - birth_year

print("Hi,", name)
print("You are", age, "years old.")
print("Your favorite number is", fav_number)

Summary

Let’s quickly revisit what we covered:

  • Variables help you store and label data
  • Python recognizes several types like text, numbers, and true/false values
  • You can run simple calculations using basic operators
  • Comments make your code easier to read
  • Always double-check what types of data you’re working with

What’s Next?

Now that you can handle simple values and operations, the next step is making decisions in your programs. 

In the next post, we’ll explore conditions and control flow — things like if, else, and how Python reacts based on what’s true or false.

If you missed our last lesson on getting started with Python, take a quick visit to catch up!

Keep experimenting and breaking things — that’s how you learn what works!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top