Variables and Data Types in Python
Introduction
This lesson is part of our complete Python course for beginners. In this lesson, you will learn about variables and data types in Python, which are the foundation of writing any Python program.
Understanding variables and data types in Python is essential because every program stores and processes data.
What are Variables in Python?
Variables in Python are used to store data values. They act as containers that hold information which can be used and modified in a program.
Example:
x = 10
name = “John”
In this example, x stores a number and name stores text.
Rules for Creating Variables
When creating variables in Python, follow these rules:
- Variable names must start with a letter or underscore
- They cannot start with a number
- They are case-sensitive
- Avoid using reserved keywords
What are Data Types in Python?
Data types define the type of value a variable can hold. Python automatically detects the data type based on the assigned value.
Common Data Types in Python
1. Integer (int)
Stores whole numbers
Example:
age = 25
2. Float (float)
Stores decimal numbers
Example:
price = 99.99
3. String (str)
Stores text data
Example:
name = “Python”
4. Boolean (bool)
Stores True or False values
Example:
is_active = True
Type Checking in Python
You can check the type of a variable using the type() function.
Example:
x = 10
print(type(x))
Why Variables and Data Types are Important
Variables and data types in Python help you:
- Store and manage data
- Perform operations on data
- Build logic in programs
Therefore, understanding variables and data types in Python is a crucial step in programming.
Internal Link
Explore full Python Course for Beginners
Conclusion
Now you understand variables and data types in Python and how they are used to store different types of data.
In the next lesson, you will learn about operators in Python.
Next Lesson
Operators in Python



