Data Types in Python
Data types in Python define the kind of value a variable can store, such as numbers, text, or True/False values. They help Python understand how to store and use information correctly. Every value in Python belongs to a particular data type.
Real-Life Analogy
Data types are like different containers used for different items.
- A bottle stores liquids.
- A box stores books.
- A folder stores papers.
Similarly, Python uses different data types to store different kinds of information.
What are Data Types?
Data types tell us what kind of value a variable is storing. Some variables store numbers, some store text, and some store only True or False values. Python automatically identifies the data type based on the value assigned.
Common Data Types in Python
Integer (int)
An integer (int) is used to store whole numbers without decimals. It is commonly used for age, marks, counting, and quantities.
Examples: 10, 25, 100
age = 10
print(age)
Output
10
Float (float)
A float is used to store decimal numbers. It is useful for values like price, height, weight, and measurements.
Examples: 10.5, 99.9
price = 99.5
print(price)
Output
99.5
String (str)
A string is used to store text or words. Strings must always be written inside quotation marks.
Examples: "Hello", "Python"
name = "VMS"
print(name)
Output
VMS
Boolean (bool)
A boolean stores only two values:
- True
- False
It is used for yes/no or true/false conditions.
is_student = True
print(is_student)
Output
True
Practical Example
Think of data types like different boxes:
- Numbers → Number box (int, float)
- Text → Text box (string)
- Yes/No → True/False box (boolean)
Each data type stores a specific kind of information.
Example -1
age = 12
height = 5.2
name = "Ravi"
is_happy = True
print(age, height, name, is_happy)
Output
12 5.2 Ravi True
Example -2
marks = 95
temperature = 36.5
student = "Rahul"
present = True
print(marks)
print(temperature)
print(student)
print(present)
Output
95
36.5
Rahul
True
Example -3
x = 50
y = 8.5
message = "Python"
status = False
print(x, y, message, status)
Output
50 8.5 Python False
Checking Data Type in Python
We can check a variable’s data type using the type() function.
x = 10
print(type(x))
Output
<class 'int'>
● This helps identify which data type is used.
➤ Key Points
● int → Whole numbers (10, 25, 100)
● float → Decimal numbers (10.5, 99.9)
● string → Text ("Hello", "Python")
● boolean → True or False
● Python automatically detects the data type
➤ Tips for Students
● Use quotes (" ") or (' ') for strings
● Do not use quotes for numbers
● Boolean values must be True or False
● Use correct data types to avoid errors
● Practice by creating your own variables
➤ Why Data Types Are Important
Data types help Python know how to work with values correctly. Using the correct data type prevents mistakes and makes programs run properly. They are an important part of learning Python programming.
Data types in Python define the kind of data stored in variables. The main Python data types are int, float, string, and boolean. Python automatically identifies the data type, which makes coding simple and beginner-friendly.