Learn Python variables and data types in simple words. This beginner-friendly tutorial covers strings, integers, booleans, lists, dictionaries, and more with examples.
If you’re just starting your Python journey, one of the first and most important things you need to understand is variables and data types. Think of them as the foundation of every Python program you’ll ever write.
In this post, we’ll break it down in simple words. You’ll learn:
- What variables are
- How to create them
- What different data types exist
- Real-world examples
Let’s dive in!
What is a Variable?
A variable is like a container that stores information. In Python, you can store data like numbers, text, or even a list of items inside a variable and use it later.
Simple Example:
name = "Tejas"
age = 25
name
is a variable storing a text value ("Tejas"
)age
is a variable storing a number (25
)
You can think of it like labeling boxes:
Box labeled ‘name’ contains: Tejas
Box labeled ‘age’ contains: 25
Rules for Naming Variables in Python
Before you start using variables, keep these simple rules in mind:
✅ Can contain letters, numbers, and underscores
✅ Must start with a letter or underscore
✅ Case-sensitive (Name
and name
are different)
❌ Cannot start with a number
❌ Cannot use spaces or special characters
Valid examples:
first_name = "Amit"
_total = 100
marks2 = 75
Invalid examples:
2marks = 75 # ❌ starts with a number
my-name = "Amit" # ❌ contains a hyphen
Common Data Types in Python
Python is dynamically typed, which means you don’t need to tell Python what type of data you are storing — it figures it out for you!
Let’s look at the most common data types:
String (str) – Text
greeting = "Hello"
Strings are always enclosed in quotes (' '
or " "
).
Integer (int) – Whole numbers
roll_number = 101
Float (float) – Decimal numbers
percentage = 85.6
Boolean (bool) – True or False
is_passed = True
List (list) – Collection of items
fruits = ["apple", "banana", "mango"]
Lists are enclosed in square brackets and can store multiple values.
Tuple (tuple) – Immutable list
dimensions = (10, 20)
Tuples are like lists, but you can’t change their values after creation.
Dictionary (dict) – Key-Value pairs
student = {"name": "Anjali", "age": 22}
Used for structured data. Think of it like a mini-database.
Read More: Introduction to Python
Checking Data Type with type()
Want to check what type of data a variable is holding? Use the built-in type()
function.
x = 42
print(type(x)) # Output: <class 'int'>
Try it with different data types:
print(type("SmartTejas"))
print(type(3.14))
print(type(True))
Type Conversion in Python
Sometimes, you may want to change a variable from one data type to another. This is called type casting.
Example:
x = "100"
y = int(x) # Converts string to integer
print(y + 50) # Output: 150
Common conversions:
- int() → to integer
- float() → to float
- str() → to string
- bool() → to boolean
Real-Life Example: Student Report
name = "Ritu"
math = 90
science = 85
average = (math + science) / 2
passed = True
print("Student Name:", name)
print("Average Marks:", average)
print("Passed:", passed)

FAQs – Python Variables and Data Types
Summary
Here’s what you learned today:
Concept | Example |
---|---|
Variable | name = “Amit” |
String | “SmartTejas” |
Integer | age = 25 |
Float | pi = 3.14 |
Boolean | is_login = True |
List | colors = [“red”, “blue”] |
Tuple | marks = (80, 90) |
Dictionary | {“name”: “Ravi”, “age”: 20} |
Mastering variables and data types is the first big step in Python programming. Practice creating your own variables and experimenting with different types.
What’s Next?
In the next post, we’ll learn about the Input and Output in Python